Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Doom: builds from other WADs, Doom II's cast and the bunny ending, cheats menu fixed, README and pictures
Mason363f4e6ca56b849
diff --git a/docs/media/doom.gif b/docs/media/doom.gifindex 1c460933..fae1e641 100644Binary files a/docs/media/doom.gif and b/docs/media/doom.gif differdiff --git a/docs/media/gallery/doom.gif b/docs/media/gallery/doom.gifindex 76db2c14..4db16d0c 100644Binary files a/docs/media/gallery/doom.gif and b/docs/media/gallery/doom.gif differdiff --git a/docs/media/thumb_doom.png b/docs/media/thumb_doom.pngindex ce9796ca..3fcce685 100644Binary files a/docs/media/thumb_doom.png and b/docs/media/thumb_doom.png differdiff --git a/games/doom/README.md b/games/doom/README.mdindex 60088385..81ef8671 100644--- a/games/doom/README.md+++ b/games/doom/README.md@@ -13,7 +13,7 @@<p align="center"><a href="https://github.com/Mason363/NumPlay/releases/latest/download/Doom.nwa"><b>Download Doom.nwa</b></a>- · <a href="#controls">Controls</a>+ · <a href="#controls">Controls</a> · <a href="#doom-from-your-own-wad">Your own WAD</a></p><p align="center">@@ -26,8 +26,11 @@* **Knee-Deep in the Dead, all of it:** Hangar, Nuclear Plant, Toxin Refinery, Command Control, Phobos Lab, Central Processing, Computer Station, Phobos Anomaly and the secret Military Base, with their secrets, keys, switches and the Barons of Hell at the end.* **Everything from the shareware WAD:** every wall, floor, sprite, menu and screen, the status bar with the marine's face, the automap, the intermission maps of Phobos with your kills, items, secrets and time, and the episode's ending.* **The whole 320 x 200 picture:** drawn at Doom's own resolution with its light levels and its palette, the screen flashing red when you're hurt and gold when you pick something up, and stretched to the calculator's 320 x 240 the way monitors of the day made Doom's pixels a little taller.-* **The five skill levels,** from I'm too young to die to Nightmare!, and the menus as they were: New Game, Options, Load Game, Save Game, Read This! and Quit Game.-* **Saved like in the game:** six save slots, named after their level. Home keeps the moment you were at, and the next start puts you back there. Your saves are also copied into `doom_saves.py`, so installing the app again doesn't erase them.+* **The five skill levels,** from I'm too young to die to Nightmare!, and the menus as they were: New Game, Options, Load Game, Save Game, Read This! and Quit Game, with their questions and Doom's quit messages.+* **All of vanilla's options:** messages, Graphic Detail (high, or low with its blocky double pixels), Screen Size from the smallest view in its border to the full screen without the status bar, five levels of brightness, and the automap's follow mode, grid, marks and zoom.+* **The calculator's own options:** every key can do any action (Options, Keys), the automap can lie over the game, secret areas can show on it in their own colour, and a Cheats menu has every code: god mode, all weapons and keys, no clipping, warping, the powers, the whole map and the chainsaw. The codes can be typed too, letters and all.+* **Saved like in the game:** six save slots, named after their level, and Quick Save and Quick Load. Home keeps the moment you were at, and the next start puts you back there. Your saves are also copied into `doom_saves.py`, so installing the app again doesn't erase them.+* **Your own WAD:** build `Doom.nwa` from Doom, The Ultimate Doom, Doom II, Final Doom, Freedoom or your own maps, as many as fit in the calculator ([below](#doom-from-your-own-wad)).<table><tr>@@ -50,11 +53,19 @@<td align="center"><img src="docs/keys.png" width="390" alt="The calculator's keys, in Read This!"><br><sub>Read This!: the calculator's keys</sub></td><td align="center"><img src="docs/ending.png" width="390" alt="The episode's ending"><br><sub>The end of Knee-Deep in the Dead</sub></td></tr>+ <tr>+ <td align="center"><img src="docs/options.png" width="390" alt="The Options menu"><br><sub>Options: detail, screen size, keys, cheats</sub></td>+ <td align="center"><img src="docs/cheats.png" width="390" alt="The Cheats menu"><br><sub>The Cheats menu</sub></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/border.png" width="390" alt="A smaller screen size in its border"><br><sub>A smaller screen, as vanilla Doom shrinks it</sub></td>+ <td align="center"><img src="docs/freedoom.png" width="390" alt="Freedoom: Phase 2, built from its WAD"><br><sub>Freedoom: Phase 2, built from its own WAD</sub></td>+ </tr></table>## How to play-Press a key on the title screen for the menu, then choose New Game, Knee-Deep in the Dead and a skill level. Find the exit of each level, shooting what gets in your way: keycards open the doors of their colour, and walls that look a little different may hide a secret. Back opens the menu (and pauses the game), where you can save, load, change the options or read the keys again.+Press a key on the title screen for the menu, then choose New Game, Knee-Deep in the Dead and a skill level. Find the exit of each level, shooting what gets in your way: keycards open the doors of their colour, and walls that look a little different may hide a secret. Back opens doors and presses switches. EXE (or ⌫) opens the menu and pauses the game, where you can save, load, change the options or read the keys again.## Controls@@ -63,33 +74,79 @@ Press a key on the title screen for the menu, then choose New Game, Knee-Deep in| Up / Down | Walk forward / back || Left / Right | Turn || OK | Fire |-| ⌫ or EXE | Use: open doors, press switches |+| Back | Use: open doors, press switches |+| EXE or ⌫ | Menu (and pause) || shift (held) | Strafe with Left and Right || x,n,t / var | Strafe left / right || alpha (held) | Run || 1 to 7 | Choose a weapon |-| Toolbox | Automap (+ and − zoom, × follows you, ÷ shows the grid, 0 shows the whole map) |+| Toolbox | Automap: the map, the map over the game, the game |+| + / − | Screen size; on the automap, zoom |+| × / ÷ / 0 | Automap: follow you, grid, the whole map |+| 8 / 9 | Automap: mark the spot, clear the marks || √ | Brightness |-| Back | Menu and pause; back one menu |+| ln / log | Quick Save / Quick Load |+| π | Pause |+| ans | Type a cheat code || Home | Keep the moment and quit |-In menus, the arrows choose, OK or EXE confirms and Back goes back. When the game asks a question, OK says yes and Back says no. Read This! in the menu shows these keys, and the very first game starts with a word on them.+In menus, the arrows choose, OK or EXE confirms and Back goes back. When the game asks a question, OK says yes and Back says no. Read This! in the menu shows the keys as they are, and the very first game starts with a word on them.++**Options, Keys** gives any key any action: choose an action, press the key (it shows each action's keys, on pages that Left and Right turn; THE KEYS AS THEY CAME puts them back). The keys and the options are kept in `doom.cfg`.++**Options, More Options**: Brightness (off and four levels, as vanilla's gamma), Map over the view (the automap's second mode), Secrets on the map (the walls of secret areas in their own colour), and Screen refresh (which way the calculator's panel is refreshed, see below).++**Options, Cheats**: God mode (IDDQD), all weapons and keys (IDKFA), weapons and ammo (IDFA), no clipping (IDCLIP), warp (IDCLEV, Left and Right choose the level), a power (IDBEHOLD: invulnerability, strength, invisibility, radiation suit, the map, light amplification), the whole map (IDDT) and the chainsaw (IDCHOPPERS). The last line, or the ans key in the game, lets you type any code, IDMYPOS and IDSPISPOPD too: the letter keys type what is written above them in alpha, numbers are typed as they are.## Good to know* **No sound:** the calculator has no speaker, so Doom plays in silence.* **Saves:** a save takes a few KB of the calculator's 42 KB of files, and its copy in `doom_saves.py` as much again. If there is no room, the game says so: delete a slot or an old script.-* **Its own pace:** the game thinks 35 times a second, as Doom always did, and draws up to 35 frames a second. Where a room is too much for the calculator, it draws fewer frames, but monsters, doors and you keep their speed.-* **The odd black stripe:** a frame has room for 3,600 slices of wall and sprite, as in RP2040 Doom. In the very busiest views, a narrow black stripe can flash for a frame where they run out.-* **Only the shareware episode:** the registered episodes (The Shores of Hell and Inferno) are not part of the free shareware WAD.+* **Its own pace:** the game thinks 35 times a second, as Doom always did, and draws up to 35 frames a second. On the N0120, every view of all nine levels is drawn within 1/35 s. On the N0110, about nine views in ten are; where a room is too much, it draws fewer frames (low detail helps), but monsters, doors and you keep their speed.+* **No tearing:** the calculator's panel refreshes itself from its memory 40 times a second, a column at a time. Each part of a frame is sent once the panel has gone past it and before it comes back, so the panel never shows two frames at once. If your calculator's panel refreshes the other way (some may), choose Right to left in More Options.+* **Only the shareware episode:** the registered episodes (The Shores of Hell and Inferno) are not part of the free shareware WAD, but you can [build Doom from yours](#doom-from-your-own-wad).++## Doom from your own WAD++The release's `Doom.nwa` has the shareware episode. With the WAD of a Doom you own, or a free one, you can make your own: in `games/doom`, `make WAD=` packs the maps you choose and builds `output/doom.nwa`, to install as `Doom.nwa` in place of the release's.++```sh+cd games/doom+make check WAD=path/to/doom2.wad MAPS="MAP01 MAP02" # Doom II's first two maps+make check WAD=path/to/doom.wad MAPS=E2M1-E2M3 # the start of The Shores of Hell+make check WAD=path/to/freedoom2.wad MAPS=MAP01-MAP02 # Freedoom: Phase 2+make check WAD=path/to/doom2.wad PWAD=mymap.wad MAPS=MAP01 # your own map, over Doom II's+make test WAD=... MAPS=... # plays it on a computer first+```++`check` builds it and checks it fits (it says so if it does not); `make WAD=...` alone just builds it. It needs what the shareware build needs (`arm-none-eabi-gcc`, nwlink) and Python 3.++**What fits.** An app gets 2 MB of the calculator's flash (2,031,616 bytes) and the engine takes 220 KB of it, so about 1.8 MB is left for the WAD. A whole Doom, Doom II or Freedoom is 10 to 15 MB even packed, so a build has a few maps: only what they can show goes in (their walls and floors, the sprites of their monsters and items and of what those turn into or fire, the weapons, and the screens of their episode), never the sounds or the music, as the calculator has no speaker. id's own maps are smaller than Freedoom's, whose pictures are more detailed. Measured with Freedoom 0.13:++| WAD | Maps | Packed | `Doom.nwa` (`doom.bin`) | |+| --- | --- | --- | --- | --- |+| `freedoom1.wad` | E1M1 | 1,350,344 bytes | 1,569,924 bytes | fits, 450 KB to spare |+| `freedoom1.wad` | E3M8 | 1,608,004 bytes | 1,827,584 bytes | fits (with the end of the third episode) |+| `freedoom1.wad` | E1M1 E1M2 | 1,923,516 bytes | 2,143,096 bytes | 112 KB too big |+| `freedoom2.wad` | MAP01 | 1,167,888 bytes | 1,387,468 bytes | fits |+| `freedoom2.wad` | MAP01-MAP02 | 1,498,260 bytes | 1,717,840 bytes | fits |+| `freedoom2.wad` | MAP01-MAP03 | 1,843,164 bytes | 2,062,744 bytes | 31 KB too big |+| `freedoom2.wad` | MAP07 | 2,051,912 bytes | 2,271,492 bytes | too big: its monsters' pictures |+| `freedoom2.wad` | MAP30 | 2,055,744 bytes | 2,275,324 bytes | too big: the Icon of Sin brings every monster |++**Choosing the maps.** `MAPS` takes map names (`E2M3`, `MAP07`), whole episodes (`E2`) and ranges (`MAP01-MAP06`), separated by spaces; without it, every map is taken (only a small WAD fits). In the game, each map leads to the next one in the build (a secret exit to a map left out goes on as the normal exit); after the last one, the episode ends, or for Doom II the game, with its text and cast of monsters. New Game starts at the first map of the episode chosen, an episode with none says so, IDCLEV and the Cheats menu warp only to the maps in the build, and the title skips the demos of maps left out.++**Which Doom.** The WAD's file name says which game it is, as for Chocolate Doom: keep it (`doom.wad`, `doom2.wad`, `tnt.wad`, `plutonia.wad`, `freedoom1.wad`, `freedoom2.wad`...). Doom II's maps play with all its monsters and the super shotgun, its intermission texts and its cast at the end; the third episode of Doom ends with its scrolling picture. PWADs go over the IWAD in the order given (`PWAD="a.wad b.wad"`): their maps, textures, flats and sprites replace the IWAD's of the same name or are added, as Chocolate Doom's `-merge` does. They must be maps for vanilla Doom (not Boom's, ZDoom's or Hexen's).++**If a map does not go in,** the build says why: a level can have up to 255 different wall textures, 511 sectors, 253 tags and 32,767 vertexes. Its things must also fit in the 130 KB of RAM the calculator gives an app, as id's and Freedoom's do; a huge map made for modern ports may not, and the game then stops with an error. `make test` plays each map of the build on a computer. Only Freedoom has been tried so far, as id's WADs are not free to share; the shareware DOOM1.WAD goes through the same tool (`make check WAD=build/ref/doom1.wad`).## How it's madeThe calculator gives an app about 130 KB of RAM: Doom on a PC asked for 4 MB. This port runs Graham Sanderson's [RP2040 Doom](https://github.com/kilograham/rp2040-doom), which made all of the shareware DOOM1.WAD playable on a 264 KB microcontroller: the WAD is packed into its WHD format (1.4 MB without the sounds and music, read in place from flash), the levels are never copied to RAM, and the game's objects are squeezed with 16-bit pointers.-The calculator has less RAM still, and no room for a frame buffer: the screen is drawn 40 rows at a time. Each frame the engine walks the level once and keeps every column of wall, floor and sprite it would draw; then each band of rows is drawn from those lists, its floors and ceilings first, then its walls and things, texture by texture, and pushed to the screen through Doom's palette.+The calculator has less RAM still, and no room for a frame buffer: the screen is drawn in five bands of 64 columns. Each frame the engine walks the level once and keeps every column of wall and floor it would draw, then draws each band whole, its floors and ceilings, walls, then its sprites, masked walls and weapon in vanilla's order, clipped as vanilla clips them; then the status bar, messages and menus, and sends it to the screen through Doom's palette. The picture is vanilla's to the pixel: the three demos play tic for tic as in Chocolate Doom, and their frames match Chocolate Doom's (but for a few pixels where vanilla reads past the end of a texture).-`make` builds `output/doom.nwa` (needs `arm-none-eabi-gcc` and Node.js for nwlink). `make test` plays it on a computer with the sanitizers on, and `make media` takes the pictures on this page from there. `python3 tools/fetch.py build/ref` downloads the shareware DOOM1.WAD and `make data WAD=build/ref/doom1.wad` packs it again into `src/doom1.whx`.+`make` builds `output/doom.nwa` (needs `arm-none-eabi-gcc` and Node.js for nwlink). `make test` plays it on a computer with the sanitizers on, and `make media` takes the pictures on this page from there. `python3 tools/fetch.py build/ref` downloads the shareware DOOM1.WAD and `make data WAD=build/ref/doom1.wad` packs it again into `src/doom1.whx`. `tools/fps.py` measures the frame rate of every level in the emulator, from every spot of each map.## Creditsdiff --git a/games/doom/docs/automap.png b/games/doom/docs/automap.pngindex 49ab5efb..28c93a2d 100644Binary files a/games/doom/docs/automap.png and b/games/doom/docs/automap.png differdiff --git a/games/doom/docs/border.png b/games/doom/docs/border.pngnew file mode 100644index 00000000..b981e5adBinary files /dev/null and b/games/doom/docs/border.png differdiff --git a/games/doom/docs/cheats.png b/games/doom/docs/cheats.pngnew file mode 100644index 00000000..764e7c26Binary files /dev/null and b/games/doom/docs/cheats.png differdiff --git a/games/doom/docs/ending.png b/games/doom/docs/ending.pngindex 5306ba7b..4c8251c5 100644Binary files a/games/doom/docs/ending.png and b/games/doom/docs/ending.png differdiff --git a/games/doom/docs/fight.png b/games/doom/docs/fight.pngindex 907e134e..a23876e7 100644Binary files a/games/doom/docs/fight.png and b/games/doom/docs/fight.png differdiff --git a/games/doom/docs/freedoom.png b/games/doom/docs/freedoom.pngnew file mode 100644index 00000000..6c363910Binary files /dev/null and b/games/doom/docs/freedoom.png differdiff --git a/games/doom/docs/hangar.png b/games/doom/docs/hangar.pngindex 1c2a0190..239edef6 100644Binary files a/games/doom/docs/hangar.png and b/games/doom/docs/hangar.png differdiff --git a/games/doom/docs/imps.png b/games/doom/docs/imps.pngindex 268f330f..297ee637 100644Binary files a/games/doom/docs/imps.png and b/games/doom/docs/imps.png differdiff --git a/games/doom/docs/intermission.png b/games/doom/docs/intermission.pngindex 316ede9a..67802ad9 100644Binary files a/games/doom/docs/intermission.png and b/games/doom/docs/intermission.png differdiff --git a/games/doom/docs/keys.png b/games/doom/docs/keys.pngindex 15bcf77b..b2fdbf8f 100644Binary files a/games/doom/docs/keys.png and b/games/doom/docs/keys.png differdiff --git a/games/doom/docs/lab.png b/games/doom/docs/lab.pngindex 78b9e457..5227cd18 100644Binary files a/games/doom/docs/lab.png and b/games/doom/docs/lab.png differdiff --git a/games/doom/docs/menu.png b/games/doom/docs/menu.pngindex 3271f86d..7b5dad06 100644Binary files a/games/doom/docs/menu.png and b/games/doom/docs/menu.png differdiff --git a/games/doom/docs/options.png b/games/doom/docs/options.pngnew file mode 100644index 00000000..4c1c8dd7Binary files /dev/null and b/games/doom/docs/options.png differdiff --git a/games/doom/src/doom/d_main.c b/games/doom/src/doom/d_main.cindex 4777748b..c13e0461 100644--- a/games/doom/src/doom/d_main.c+++ b/games/doom/src/doom/d_main.c@@ -2211,8 +2211,9 @@ void D_DoomMain (void){// (tests: straight into a level, on Ultra-Violence)autostart = true;- startepisode = nw_warp / 10;- startmap = nw_warp % 10;+ // (EM: episode E, map M; Doom II: the map's number)+ startepisode = gamemode == commercial ? 1 : nw_warp / 10;+ startmap = gamemode == commercial ? nw_warp : nw_warp % 10;startskill = sk_hard;}if (nw_resume_ready())diff --git a/games/doom/src/doom/f_finale.c b/games/doom/src/doom/f_finale.cindex 7466ffbd..8f5a1225 100644--- a/games/doom/src/doom/f_finale.c+++ b/games/doom/src/doom/f_finale.c@@ -363,6 +363,28 @@ int castonmelee;boolean castattacking;+#if NUMWORKS+// (a build of chosen maps, tools/pick.py, has the pictures of the monsters in its maps: the cast goes past the+// others, whose pictures are empty)+static boolean F_NwCastMissing(void)+{+ const state_t *st = &states[mobjinfo[castorder[castnum].type].seestate];+ spriteframeref_t f = sprite_frame(st->sprite, st->frame & FF_FRAMEMASK);+ int lump = spriteframe_rotates(f) ? spriteframe_rotated_pic(f, 0) : spriteframe_unrotated_pic(f);+ return sprite_width(lump) <= FRACUNIT;+}++static void F_NwCastNext(void)+{+ for (int i = 0; i < 20 && F_NwCastMissing(); i++)+ {+ castnum++;+ if (castorder[castnum].name == NULL)+ castnum = 0;+ }+}+#endif+//// F_StartCast//@@ -371,6 +393,9 @@ void F_StartCast (void)if (finalestage == F_STAGE_CAST) return; // seems to be a bug in general, but seems easier for us to start the cast wipe multiple timeswipegamestate = -1; // force a screen wipecastnum = 0;+#if NUMWORKS+ F_NwCastNext();+#endifcaststate = &states[mobjinfo[castorder[castnum].type].seestate];casttics = state_tics(caststate);castdeath = false;@@ -400,6 +425,9 @@ void F_CastTicker (void)castdeath = false;if (castorder[castnum].name == NULL)castnum = 0;+#if NUMWORKS+ F_NwCastNext();+#endifif (mobjinfo[castorder[castnum].type].seesound)S_StartSound (NULL, mobjinfo[castorder[castnum].type].seesound);caststate = &states[mobjinfo[castorder[castnum].type].seestate];@@ -607,6 +635,31 @@ void F_CastDrawer (void)}#endif+#if NUMWORKS+// the calculator draws the screens band by band (nw/nw_back.inc): how far the third episode's ending has+// scrolled from PFUB2 to PFUB1 (vanilla's F_BunnyScroll), and "THE END" over it+int F_NwBunnyScrolled(void)+{+ int scrolled = (320 - ((signed int) finalecount - 230) / 2);+ if (scrolled > 320)+ scrolled = 320;+ if (scrolled < 0)+ scrolled = 0;+ return scrolled;+}++void F_NwBunnyPatches(void)+{+ int stage;+ if (finalecount < 1130)+ return;+ stage = finalecount < 1180 ? 0 : (finalecount - 1180) / 5;+ if (stage > 6)+ stage = 6;+ V_DrawPatch((SCREENWIDTH - 13 * 8) / 2, (SCREENHEIGHT - 8 * 8) / 2, VPATCH_NAME(END0) + stage);+}+#endif+//// F_DrawPatchCol//diff --git a/games/doom/src/doom/f_finale.h b/games/doom/src/doom/f_finale.hindex 2d278908..b79081fa 100644--- a/games/doom/src/doom/f_finale.h+++ b/games/doom/src/doom/f_finale.h@@ -61,5 +61,9 @@ void F_BunnyDrawPatches(void);#endif// return the sprite to to draw or -1-x to draw x flippedint F_CastSprite(void);+#if NUMWORKS+int F_NwBunnyScrolled(void);+void F_NwBunnyPatches(void);+#endifvoid F_CastDrawer (void);#endifdiff --git a/games/doom/src/doom/m_menu.c b/games/doom/src/doom/m_menu.cindex 12736029..ee165996 100644--- a/games/doom/src/doom/m_menu.c+++ b/games/doom/src/doom/m_menu.c@@ -867,8 +867,12 @@ void M_SaveSelect(int choice)// (no letters to type on a calculator: the save is named after the level, OK saves it){extern const constcharstar mapnames[];+ extern const char * const mapnames_commercial[];if (gamemode != commercial && gameepisode >= 1 && gameepisode <= 4 && gamemap >= 1 && gamemap <= 9)M_StringCopy(savegamestrings[choice], mapnames[(gameepisode - 1) * 9 + gamemap - 1], SAVESTRINGSIZE);+ else if (gamemode == commercial && gamemap >= 1 && gamemap <= 32)+ M_StringCopy(savegamestrings[choice], mapnames_commercial[gamemap - 1+ + (gamemission == pack_plut ? 32 : gamemission == pack_tnt ? 64 : 0)], SAVESTRINGSIZE);}#endifif (!strcmp(savegamestrings[choice], EMPTYSTRING))@@ -1040,7 +1044,7 @@ static const struct { const char *what; uint8_t actions[4]; } keys_page[] = {void M_DrawKeys(void){static const char title[] = "THE CALCULATOR'S KEYS";- static const char weapons[] = "WEAPONS: THEIR NUMBERS. HOME KEEPS THE MOMENT.";+ static const char weapons[] = "WEAPONS: THEIR NUMBERS. HOME: KEEP, QUIT.";static const char menus[] = "IN MENUS: ARROWS, OK, BACK. OPTIONS: KEYS.";int y = 20;@@ -1078,7 +1082,8 @@ void M_DrawReadThis2(void)}#endif#if NUMWORKS- inhelpscreens = 2; // (the order page: HELP1's keys are a PC's)+ // (the order page: HELP1's keys are a PC's; The Ultimate Doom has only this page: the calculator's keys)+ inhelpscreens = gameversion >= exe_ultimate ? 4 : 2;#elseinhelpscreens = 1;#endif@@ -1099,7 +1104,11 @@ void M_DrawReadThisCommercial(void)return;}#endif+#if NUMWORKS+ inhelpscreens = 4; // (the calculator's keys, not HELP's)+#elseinhelpscreens = 3;+#endif#if !USE_WHDV_DrawPatchDirect(0, 0, W_CacheLumpName(DEH_String("HELP"), PU_CACHE));@@ -1197,6 +1206,20 @@ void M_NewGame(int choice)#if NET_MENUEpiDef.prevMenu = &MainDef;netgame_choice = -1;+#endif+#if NUMWORKS+ // (a build of chosen maps: the cursor starts on an episode that has some)+ if (gamemode != commercial && !G_NwNextMapIn(EpiDef.lastOn + 1, 1, 9))+ {+ for (int e = 0; e < EpiDef.numitems; e++)+ {+ if (G_NwNextMapIn(e + 1, 1, 9))+ {+ EpiDef.lastOn = e;+ break;+ }+ }+ }#endifif (gamemode == commercial || gameversion_is_chex(gameversion))M_SetupNextMenu(&NewDef);diff --git a/games/doom/src/doom/p_setup.c b/games/doom/src/doom/p_setup.cindex 570795e9..05a9103e 100644--- a/games/doom/src/doom/p_setup.c+++ b/games/doom/src/doom/p_setup.c@@ -87,6 +87,7 @@ line_t* lines;uint8_t num_switched_sides = 0;#if WHD_SUPER_TINYconst side_t* sides_z;+const uint8_t *nw_side_textures;uint16_t whd_sidemul;uint16_t whd_vmul;#else@@ -667,6 +668,12 @@ void P_LoadSideDefs (int lump)printf("SIDEDEF LOAD map ? sides size = %08x\n", W_LumpLength(lump));#endifsides_z = (const side_t *) W_CacheLumpNum (lump,PU_LEVEL);+ {+ // (the level's wall textures, after its sides: whd_gen)+ int len = W_LumpLength(lump);+ int n = sides_z[len - 2] | sides_z[len - 1] << 8;+ nw_side_textures = sides_z + len - 2 - 2 * n;+ }#elsestatic_assert(sizeof(side_t)==12, "");numsides = W_LumpLength (lump) / sizeof(side_t); // todo should really be packed?diff --git a/games/doom/src/doom/r_state.h b/games/doom/src/doom/r_state.hindex e0fc1980..383506de 100644--- a/games/doom/src/doom/r_state.h+++ b/games/doom/src/doom/r_state.h@@ -273,23 +273,32 @@ static inline uint side_sectornum(side_t *side) {}#define side_sector(side) (sectors + side_sectornum(side))+// the level's wall textures: a side gives them by their place in this table (whd_gen)+extern const uint8_t *nw_side_textures;+static inline int side_texture(int k) {+ return nw_side_textures[2 * k] | nw_side_textures[2 * k + 1] << 8;+}+static inline int side_toptexture(side_t *side) {if ((side[0] & 0xf) < 5) return 0;- return side[2] <= LAST_SWITCH_TEXTURE ? check_switch_texture(side, CST_TOP, side[2]) : side[2];+ int t = side_texture(side[2]);+ return t <= LAST_SWITCH_TEXTURE ? check_switch_texture(side, CST_TOP, t) : t;}static inline int side_midtexture(side_t *side) {static uint8_t posM[26] = { 0, 0, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3};uint enc = side[0] & 0xf;if (!posM[enc]) return 0;- return side[posM[enc]] <= LAST_SWITCH_TEXTURE ? check_switch_texture(side, CST_MID, side[posM[enc]]) : side[posM[enc]];+ int t = side_texture(side[posM[enc]]);+ return t <= LAST_SWITCH_TEXTURE ? check_switch_texture(side, CST_MID, t) : t;}static inline int side_bottomtexture(side_t *side) {static uint8_t posB[26] = { 0, 2, 0, 2, 3, 0, 2, 3, 0, 2, 3, 4, 0, 2, 3, 4};uint enc = side[0] & 0xf;if (!posB[enc]) return 0;- return side[posB[enc]] <= LAST_SWITCH_TEXTURE ? check_switch_texture(side, CST_BOTTOM, side[posB[enc]]) : side[posB[enc]];+ int t = side_texture(side[posB[enc]]);+ return t <= LAST_SWITCH_TEXTURE ? check_switch_texture(side, CST_BOTTOM, t) : t;}static inline int side_textureoffset16(side_t *side) {@@ -558,10 +567,11 @@ static inline boolean line_validcount_update_check(should_be_const line_t *ld, i#define seg_offset(s) (((s)->offset) << FRACBITS)#define seg_next_step(s) 1#else-#define seg_linedef(s) (&lines[(s)[3] + ((s)[4] << 8)])+#define seg_linedef(s) (&lines[(s)[3] + (((s)[4] & 0x7f) << 8)])#define seg_side(s) ((s)[0] >> 7)-#define seg_v1(s) (&vertexes[((s)[1] | (((s)[0]&0x07)<<8))])-#define seg_v2(s) (&vertexes[((s)[2] | (((s)[0]&0x38)<<5))])+static inline int seg_vertex_high(const seg_t *s);+#define seg_v1(s) (&vertexes[((s)[1] | (((s)[0]&0x07)<<8)) | (seg_vertex_high(s) & 15) << 11])+#define seg_v2(s) (&vertexes[((s)[2] | (((s)[0]&0x38)<<5)) | (seg_vertex_high(s) >> 4) << 11])static inline fixed_t seg_offset(const seg_t *s) {if (!(s[0] & 64)) {return 0;@@ -573,20 +583,26 @@ static inline fixed_t seg_offset(const seg_t *s) {}}+static inline int seg_offset_bytes(const seg_t *s) {+ return s[0] & 64 ? (s[5] & 128 ? 2 : 1) : 0;+}+static inline int seg_next_step(const seg_t *s) {- int size = 5;- if (s[0]&64) {- size += s[5]&128 ? 2 : 1;- }+ int size = 5 + seg_offset_bytes(s);#if WHD_SEG_ANGLESsize += 2;#endif- return size;+ return size + (s[4] >> 7);+}++// (a big level's vertexes from 2048 on: the line's top bit says their top bits are in a byte at the seg's end)+static inline int seg_vertex_high(const seg_t *s) {+ return s[4] & 128 ? s[seg_next_step(s) - 1] : 0;}#if WHD_SEG_ANGLES-// the seg's angle as the WAD has it (the last two bytes of its record, whd_gen -lossless)+// the seg's angle as the WAD has it (after its offset, whd_gen -lossless)static inline angle_t seg_angle_whd(const seg_t *s) {- int p = seg_next_step(s) - 2;+ int p = 5 + seg_offset_bytes(s);return (angle_t)(s[p] | (s[p + 1] << 8)) << 16;}#endifdiff --git a/games/doom/src/doom/r_things.c b/games/doom/src/doom/r_things.cindex 0fc39fa6..75c8a3f4 100644--- a/games/doom/src/doom/r_things.c+++ b/games/doom/src/doom/r_things.c@@ -1461,6 +1461,32 @@ static void nw_draw_psprite(pspdef_t *psp, const int8_t *lights) {if (c0 <= b) nw_draw_vis_sprite(vis, c0, b);}+// Doom II's cast (f_finale.c): the monster's picture as V_DrawPatch puts it at (160, 170), in the band+void nw_draw_cast(int lump) {+ boolean flip = lump < 0;+ if (flip) lump = -1 - lump;+ int ds = detailshift;+ detailshift = 0;+ vissprite_t avis, *vis = &avis;+ vis->mobjflags = 0;+ vis->x1 = SCREENWIDTH / 2 - (sprite_offset(lump) >> FRACBITS);+ vis->x2 = vis->x1 + (sprite_width(lump) >> FRACBITS) - 1;+ vis->scale = FRACUNIT;+ vis->texturemid = centeryfrac - (170 << FRACBITS) + sprite_topoffset(lump);+ vis->xiscale = flip ? -FRACUNIT : FRACUNIT;+ vis->startfrac = flip ? sprite_width(lump) - 1 : 0;+ vis->patch = lump;+ vis->colormap = 0;+ int a = vis->x1 > nw_band_x0 ? vis->x1 : nw_band_x0;+ int b = vis->x2 < nw_band_x1 - 1 ? vis->x2 : nw_band_x1 - 1;+ for (int x = a; x <= b; x++) {+ nw_clipbot[x] = SCREENHEIGHT;+ nw_cliptop[x] = -1;+ }+ if (a <= b) nw_draw_vis_sprite(vis, a, b);+ detailshift = ds;+}+static void nw_draw_player_sprites(void) {int lightnum = (mobj_sector(viewplayer->mo)->lightlevel >> LIGHTSEGSHIFT) + extralight;const int8_t *lights = scalelight[lightnum < 0 ? 0 : lightnum >= LIGHTLEVELS ? LIGHTLEVELS - 1 : lightnum];diff --git a/games/doom/src/doom1.whx b/games/doom/src/doom1.whxindex 72694b98..b2c3e644 100644Binary files a/games/doom/src/doom1.whx and b/games/doom/src/doom1.whx differdiff --git a/games/doom/src/nw/doomconf.h b/games/doom/src/nw/doomconf.hindex ea80d44d..076910a5 100644--- a/games/doom/src/nw/doomconf.h+++ b/games/doom/src/nw/doomconf.h@@ -93,7 +93,6 @@#define NO_USE_BOUND_CONFIG 1#define USE_MEMORY_WAD 1#define NO_ZONE_DEBUG 1-#define NO_USE_FINALE_CAST 1 /* Doom II's */#define NO_USE_ENDDOOM 1/* the renderer (pd_render.cpp), with room for this many runs of pixels in the view each frame */diff --git a/games/doom/src/nw/nw_back.inc b/games/doom/src/nw/nw_back.incindex 3f262a77..8c71bfbf 100644--- a/games/doom/src/nw/nw_back.inc+++ b/games/doom/src/nw/nw_back.inc@@ -323,14 +323,15 @@ extern "C" void nw_masked_flush(void) {// ---------------------------------------------------------------------------------------------------------------// screens without the 3D view: their pictures for the band's columns-// a 320 x 200 picture's columns x0 to x1 (each decoded top to bottom, once)-static void nw_draw_splash(int patch_num, int x0, int x1) {+// a 320 x 200 picture's columns x0 to x1 (each decoded top to bottom, once), those from x0 + shift to x1 + shift+// for a picture scrolled shift columns to the left+static void nw_draw_splash(int patch_num, int x0, int x1, int shift = 0) {patch_decode_info pdi;get_patch_decoder(patch_num, &pdi);const uint16_t *col_offsets = pdi.col_offsets;const uint8_t *patch_decoder_table = get_patch_decoder_table(patch_num, pdi.decoder);int h = patch_height(pdi.patch);- for (int col = x0; col < x1; col++) {+ for (int col = x0 + shift; col < x1 + shift; col++) {uint16_t col_offset = col_offsets[col];if (0xff == (col_offset >> 8)) col_offset = col_offsets[col_offset & 0xff];th_bit_input bi;@@ -339,7 +340,7 @@ static void nw_draw_splash(int patch_num, int x0, int x1) {} else {th_bit_input_init_bit_offset(&bi, pdi.patch + pdi.data_index, col_offset);}- uint8_t *dest = render_frame_buffer + col;+ uint8_t *dest = render_frame_buffer + col - shift;uint8_t prev_pixel = 0;for (int y = 0; y < h && y < SCREENHEIGHT; y++, dest += NW_STRIDE) {uint16_t p = th_decode_table_special_16(pdi.decoder, patch_decoder_table, &bi);@@ -388,7 +389,18 @@ static void nw_draw_background(int x0, int x1, int help) {return;} else if (finalestage == F_STAGE_ARTSCREEN) {const char *ln = F_ArtScreenLumpName();- if (ln) patch_num = W_GetNumForName(ln);+ if (ln) {+ patch_num = W_GetNumForName(ln);+ } else {+ // (the third episode's: PFUB2 scrolling away to PFUB1)+ int scrolled = F_NwBunnyScrolled();+ int split = 320 - scrolled;+ if (x0 < split) nw_draw_splash(W_GetNumForName("PFUB2"), x0, x1 < split ? x1 : split, scrolled);+ if (x1 > split) nw_draw_splash(W_GetNumForName("PFUB1"), x0 > split ? x0 : split, x1, -split);+ return;+ }+ } else if (finalestage == F_STAGE_CAST) {+ patch_num = W_GetNumForName("BOSSBACK");}break;default: break;@@ -558,6 +570,9 @@ static void nw_draw_band(uint8_t *band, int x0, int x1, bool view, int help, boonw_direct = true;M_DrawKeys();nw_direct = false;+ } else if (gamestate == GS_FINALE && finalestage == F_STAGE_CAST && !help) {+ nw_scratch_base = render_col_count;+ nw_draw_cast(F_CastSprite());}}V_DrawPatchListBand(nw_patches);@@ -695,6 +710,15 @@ void pd_end_frame(int wipe_start) {} else if (gamestate == GS_LEVEL) {ST_doPaletteStuff();}+ if (gamestate == GS_FINALE && !help) {+ if (finalestage == F_STAGE_CAST) {+ // (the monster's picture is drawn as the weapon is: the frame's pictures start again)+ pd_begin_frame();+ F_CastDrawer();+ } else if (finalestage == F_STAGE_ARTSCREEN && !F_ArtScreenLumpName()) {+ F_NwBunnyPatches();+ }+ }ST_FpsDrawer(-1);if (gamestate == GS_LEVEL && gametic && !inhelpscreens) HU_Drawer();if (paused) {diff --git a/games/doom/src/nw/nw_menu.inc b/games/doom/src/nw/nw_menu.incindex ab78e405..0ed7645a 100644--- a/games/doom/src/nw/nw_menu.inc+++ b/games/doom/src/nw/nw_menu.inc@@ -102,15 +102,16 @@ static const char nw_power_codes[] = "vsiral";static const char *const nw_power_names[] = {"INVULNERABLE", "BERSERK", "INVISIBLE", "RADIATION SUIT","COMPUTER MAP", "LIGHT GOGGLES"};+boolean ST_Responder(event_t *ev);+static void M_NwType(const char *code){+ // (straight to the status bar's cheat checks, as each key typed would go: the event queue holds 8)M_ClearMenus();for (; *code; code++){event_t ev = {ev_keydown, *code, *code, 0, 0, 0};- D_PostEvent(&ev);- ev.type = ev_keyup;- D_PostEvent(&ev);+ ST_Responder(&ev);}}diff --git a/games/doom/src/nw/nw_render.h b/games/doom/src/nw/nw_render.hindex 5f549f64..fa831afe 100644--- a/games/doom/src/nw/nw_render.h+++ b/games/doom/src/nw/nw_render.h@@ -64,6 +64,7 @@ typedef struct {/* band time (r_things.c): sprites, masked walls and the weapon of the band, in vanilla's order */void nw_sort_vissprites(void);void nw_draw_masked(void);+void nw_draw_cast(int lump); /* Doom II's cast of monsters *//* ... their columns go to the back end, a sprite or a masked wall at a time */void nw_masked_column(int x, int yl, int yh, int base_offset, int fuzz);void nw_masked_flush(void);diff --git a/games/doom/tests/check.py b/games/doom/tests/check.pyindex f07c961d..47eade07 100644--- a/games/doom/tests/check.py+++ b/games/doom/tests/check.py@@ -1,9 +1,9 @@#!/usr/bin/env python3"""Checks of Doom on a computer (make test): the host build, with AddressSanitizer and UBSan, through thetitle and its demos, the menus, every level of the episode, an intermission, the ending, the saves and the-moment kept on Home.+moment kept on Home; for a build from another WAD (--wad), its maps, an exit, the menus and the saves.- python3 tests/check.py build/play"""+ python3 tests/check.py build/play [--wad]"""import osimport reimport shutil@@ -50,6 +50,59 @@ def check(cond, what):print(("ok " if cond else "FAIL"), what, flush=True)+def report():+ if failures:+ print(f"\n{len(failures)} failed:")+ for f in failures:+ print(" ", f)+ sys.exit(1)+ print("\nall good")+ sys.exit(0)+++# a build from another WAD (make test WAD=...): the title, each of its maps played, the first one's exit, a new+# game from the menus, a save and its loading+if "--wad" in sys.argv:+ mode, *maps = open(os.path.join(os.path.dirname(PLAY), "wad", "maps.txt")).read().split()++ def warp(name):+ return name[3:].lstrip("0") if name.startswith("MAP") else name[1] + name[3]++ def got(e):+ return f"MAP{e['map']:02d}" if mode == "commercial" else f"E{e['episode']}M{e['map']}"++ e = run(["--ms", "60000"], what="the title")+ if e:+ check(e["quit"] == 1, f"the title runs ({mode}, maps {' '.join(maps)}) and quits on Home")+ walk = ",".join(f"{t}-{t + 900}:up,{t + 900}-{t + 1300}:right,{t + 300}-{t + 400}:ok" for t in range(1500, 20000, 1500))+ for name in maps:+ e = run(["--warp", warp(name), "--keys", walk, "--ms", "21000"], what=name)+ if e:+ check(e["state"] == GS_LEVEL and got(e) == name and e["leveltime"] > 500,+ f"{name}: played for {e['leveltime']} tics, health {e['health']}, {e['kills']} kills, "+ f"{e['columns']} columns at most, {e['zone'] // 1024} KB of the zone")+ e = run(["--warp", warp(maps[0]), "--exit-at", "3000", "--keys", "9000:ok,11000:ok,13000:ok,15000:ok",+ "--ms", "20000"], what="the first map's exit")+ if e:+ check(e["state"] in (GS_LEVEL, GS_FINALE) and (e["state"] == GS_FINALE or got(e) in maps[1:]),+ f"{maps[0]}'s exit: {got(e) if e['state'] == GS_LEVEL else 'the ending'}")+ # (the episode menu starts on the first episode the build has)+ e = run(["--keys", "2000:ok,2700:ok,3400:ok,4100:ok,6000-8000:up", "--ms", "10000"], what="a new game")+ if e:+ check(e["state"] == GS_LEVEL and got(e) == maps[0], f"a new game from the menus starts in {got(e)}")+ saves = tempfile.mkdtemp(prefix="doom_saves_")+ e = run(["--warp", warp(maps[0]), "--keys", "1500:exe,2000:down,2300:down,2600:down,3100:ok,3700:ok,4300:ok",+ "--ms", "7000"], saves=saves, what="a save in a slot")+ if e:+ check("doomsav0.dsg" in e["files"], "saved in the first slot")+ e = run(["--keys", "2000:ok,2700:down,3000:down,3400:ok,4000:ok", "--ms", "7000"], saves=saves,+ what="loading the slot")+ if e:+ check(e["state"] == GS_LEVEL and got(e) == maps[0], "the slot loads")+ shutil.rmtree(saves, ignore_errors=True)+ report()++# the title, the credits and the three demos, which must play exactly as in Chocolate Doom 3.1.0 (vanilla Doom# 1.9): where each ends, the player there and both random number generators are Chocolate Doom's, tic for tic (the# screen melts take theirs from the second one, M_Random, as they do there)@@ -118,10 +171,4 @@ if e:check(e["state"] == GS_LEVEL and e["map"] == 1 and "doomsav0.dsg" in e["files"],"after a reinstall, the slot comes back from doom_saves.py and loads")shutil.rmtree(saves, ignore_errors=True)--if failures:- print(f"\n{len(failures)} failed:")- for f in failures:- print(" ", f)- sys.exit(1)-print("\nall good")+report()diff --git a/games/doom/tools/media.py b/games/doom/tools/media.pyindex 921e4701..ab2021d3 100644--- a/games/doom/tools/media.py+++ b/games/doom/tools/media.py@@ -57,10 +57,11 @@ media = os.path.join(ROOT, "docs", "media")os.makedirs(docs, exist_ok=True)# the title screen and the first demo, Phobos Lab: imps down a corridor, then zombiemen around the yellow key-IMPS, KEY = (9200, 12700), (35300, 38500)-title_shots = {"title": 2000, "imps": 10058, "fight": 36058, "lab": 57058}+# (the screen melts into the demo first, as in vanilla)+IMPS, KEY = (10257, 13757), (36357, 39557)+title_shots = {"title": 2000, "imps": 11115, "fight": 37115, "lab": 58114}gif_times = frames(*IMPS) + frames(*KEY)-pics = play([], list(title_shots.values()) + gif_times + [1000], 58000)+pics = play([], list(title_shots.values()) + gif_times + [1000], 59000)for name, t in title_shots.items():save_png(pics[t], os.path.join(docs, f"{name}.png"))@@ -84,9 +85,28 @@ for name, t in hangar_shots.items():save_png(pics[t], os.path.join(docs, f"{name}.png"))# Read This!: the calculator's keys-pics = play(["--keys", "2000:ok,2600:down,2900:down,3200:down,3500:down,4000:ok"], [5000], 6000)-save_png(pics[5000], os.path.join(docs, "keys.png"))+pics = play(["--keys", "2000:ok,2600:down,2900:down,3200:down,3500:down,4000:ok"], [6500], 7000)+save_png(pics[6500], os.path.join(docs, "keys.png"))# E1M8's exit: the episode's endingpics = play(["--warp", "18", "--exit-at", "3000"], [44000], 45000)save_png(pics[44000], os.path.join(docs, "ending.png"))++# the Options menu, the Cheats menu over the game, and a smaller screen with its border+pics = play(["--warp", "11", "--keys", "1500:exe,1900:down,2300:ok"], [3200], 4000)+save_png(pics[3200], os.path.join(docs, "options.png"))+cheats = "1500:exe,1900:down,2300:ok,2700:down,2900:down,3100:down,3300:down,3500:down,3900:ok"+pics = play(["--warp", "11", "--keys", cheats], [4800], 5500)+save_png(pics[4800], os.path.join(docs, "cheats.png"))+pics = play(["--warp", "11", "--keys", "1500:minus,1800:minus,2100:minus,2600-3300:up"], [3600], 4200)+save_png(pics[3600], os.path.join(docs, "border.png"))++# Freedoom: Phase 2 (its pictures are free, under the BSD license), from a build of its first two maps: the super+# shotgun in MAP02 (make host WAD=freedoom2.wad MAPS=MAP01-MAP02, that build/play copied elsewhere, then+# python3 tools/media.py build/play <its copy>)+if len(sys.argv) > 2:+ PLAY = os.path.abspath(sys.argv[2])+ cheat = ("1500:exe,2200:down,2700:ok,3200:down,3500:down,3800:down,4100:down,4400:down,4900:ok,5600:down,6200:ok,"+ "7000:3,9000-9600:up,9900-10100:right,10300-11300:up,11500:ok")+ pics = play(["--warp", "2", "--keys", cheat], [11600], 12000)+ save_png(pics[11600], os.path.join(docs, "freedoom.png"))diff --git a/games/doom/tools/pick.py b/games/doom/tools/pick.pyindex 11f50d33..1aadb6eb 100644--- a/games/doom/tools/pick.py+++ b/games/doom/tools/pick.py@@ -250,6 +250,29 @@ def unpack_sides(lumps):return [[n, bytes(lines) if n == "LINEDEFS" else bytes(out) if n == "SIDEDEFS" else v] for n, v in lumps]+def renumber_tags(name, lumps):+ """the map's tags numbered from 1 (the calculator's packed maps keep them in a byte), but for 666 and 667, which+ the bosses' deaths look for"""+ d = dict(lumps[1:])+ lines, sectors = bytearray(d["LINEDEFS"]), bytearray(d["SECTORS"])+ places = [(lines, i + 8) for i in range(0, len(lines) - 13, 14)]+ places += [(sectors, i + 24) for i in range(0, len(sectors) - 25, 26)]+ tags = {struct.unpack("<H", b[o:o + 2])[0] for b, o in places}+ kept = {0, 666, 667}+ new = {}+ if not all(t < 254 or t in kept for t in tags):+ others = sorted(tags - kept)+ if len(others) > 253:+ fail(f"{name} has {len(others)} tags: the calculator's build has room for 253")+ new = {t: k + 1 for k, t in enumerate(others)}+ for b, o in places:+ t = struct.unpack("<H", b[o:o + 2])[0]+ if b is lines and t in (666, 667):+ t = t - 666 + 254 # (as whd_gen packs the sectors' 666 and 667, and the engine knows them)+ struct.pack_into("<H", b, o, new.get(t, t))+ return [[n, bytes(lines) if n == "LINEDEFS" else bytes(sectors) if n == "SECTORS" else v] for n, v in lumps]++def renumber_bsp(lumps):"""the map's BSP tree numbered as id's node builder numbers it (the calculator's packed nodes give theirchildren as near numbers): each node after its children, a node child just before its parent (the left one@@ -369,8 +392,6 @@ def main():for item in rest:if item[0] == tl:item[1] = bytes(body)- if kept_textures > 255:- fail(f"{kept_textures} wall textures: the calculator's build has room for 255 (choose fewer maps)")sprites = needed_sprites(kept, maps)# (the markers inside, P1_START..., stay as they are)sections["S"] = [[n, d if n[:4] in sprites or n.endswith(("_START", "_END")) else EMPTY_PATCH]@@ -382,11 +403,9 @@ def main():if len(sections["F"]) > 255:fail(f"{len(sections['F'])} flats: the calculator's build has room for 255")- # (a calculator has no sound: the music and sound effects are left out, and so are the demos of maps left- # out, or recorded by other versions of Doom than 1.9)+ # (the demos of maps left out, or recorded by other versions of Doom than 1.9, are left out; the sounds and+ # music are emptied by whd_gen -silent, which reuses their places)def keep_lump(name, d):- if re.fullmatch(r"D_\w+|DS\w+|DP\w+|GENMIDI|DMXGUS\w*", name):- return Falseif re.fullmatch(r"DEMO\d", name):if len(d) < 13 or d[0] != 109:return False@@ -394,9 +413,27 @@ def main():return demo_map in keptreturn Truerest = [[n, d] for n, d in rest if keep_lump(n, d)]+ # the screens of the episodes and maps left out become empty pictures: their intermission maps, animations,+ # level names and endings (the pages the title and the menu show stay)+ unused = set()+ if mode != "commercial":+ eps = {map_order(n)[0] for n in kept}+ for e in range(1, 5):+ if e not in eps:+ unused |= {f"WIMAP{e - 1}", {2: "VICTORY2", 3: "PFUB1", 4: "ENDPIC"}.get(e, "")}+ if e == 3:+ unused |= {"PFUB2"} | {f"END{i}" for i in range(7)}+ unused |= {f"WILV{e - 1}{m - 1}" for e in range(1, 5) for m in range(1, 10) if f"E{e}M{m}" not in kept}+ prefixes = tuple(f"WIA{e - 1}" for e in range(1, 4) if e not in eps)+ else:+ unused |= {f"CWILV{m - 1:02d}" for m in range(1, 33) if f"MAP{m:02d}" not in kept}+ prefixes = ()+ # (Read This! shows the calculator's keys, and the order page HELP2 before The Ultimate Doom)+ unused |= {"HELP", "HELP1"} | ({"HELP2"} if mode in ("retail", "commercial") else set())+ rest = [[n, EMPTY_PATCH if n in unused or (prefixes and n.startswith(prefixes)) else d] for n, d in rest]out = list(rest)for name in kept:- out += renumber_bsp(unpack_sides(maps[name]))+ out += renumber_bsp(renumber_tags(name, unpack_sides(maps[name])))out.append(["NWMODE", mode.encode()])for k, (a_, b_) in SECTIONS.items():out.append([a_, b""])@@ -405,6 +442,8 @@ def main():os.makedirs(a.out, exist_ok=True)path = os.path.join(a.out, os.path.basename(a.wads[0]).lower())write_wad(path, out)+ # (for tests/check.py --wad: the game and its maps)+ open(os.path.join(a.out, "maps.txt"), "w").write(f"{mode} {' '.join(kept)}\n")print(f"pick.py: {path}: {mode}, maps {' '.join(kept)}; {kept_textures} wall textures, "f"{len(used_patches)} wall patches, {len(sections['F'])} flats, "f"{len({n[:4] for n, d in sections['S'] if d != EMPTY_PATCH})} sprites")diff --git a/games/doom/tools/whd_gen/whd_gen.cpp b/games/doom/tools/whd_gen/whd_gen.cppindex bf72e05c..b1c54317 100644--- a/games/doom/tools/whd_gen/whd_gen.cpp+++ b/games/doom/tools/whd_gen/whd_gen.cpp@@ -2405,6 +2405,19 @@ std::vector<int> convert_sidedefs(wad &wad, const texture_index &tex_index, lumphash = hash * 31 + count;if (super_tiny) {std::vector<uint8_t> sides_z;+ // the level's wall textures: its sides give them by their place in this table (in a byte), the table (after+ // the sides, then its length) gives their numbers+ std::vector<uint16_t> level_textures = {0};+ std::map<int, int> level_texture_of;+ auto level_texture = [&](int t) {+ if (!t) return 0;+ auto it = level_texture_of.find(t);+ if (it != level_texture_of.end()) return it->second;+ if (level_textures.size() == 256) fail("a level with more than 255 wall textures\n");+ level_texture_of[t] = (int) level_textures.size();+ level_textures.push_back((uint16_t) t);+ return (int) level_textures.size() - 1;+ };for (int i = 0; i < count; i++) {uint s0 = sides_z.size();auto msd = get_field_inc<mapsidedef_t>(lump.data, offset);@@ -2417,6 +2430,9 @@ std::vector<int> convert_sidedefs(wad &wad, const texture_index &tex_index, lumpif (toptexture < 0 || midtexture < 0 || bottomtexture < 0) {fail("Missing sidedef texture");}+ toptexture = level_texture(toptexture);+ midtexture = level_texture(midtexture);+ bottomtexture = level_texture(bottomtexture);// some textures may be 0, we consider the following combinations of none or the same textures...// we want to encode as few of A, B, C as possible.@@ -2560,6 +2576,12 @@ std::vector<int> convert_sidedefs(wad &wad, const texture_index &tex_index, lumpside_metaz.record(sides_z.size() - s0);}sides_z_of_level = sides_z;+ for (uint16_t t : level_textures) {+ sides_z.push_back(t & 0xff);+ sides_z.push_back(t >> 8);+ }+ sides_z.push_back(level_textures.size() & 0xff);+ sides_z.push_back(level_textures.size() >> 8);lump.data = sides_z;} else {std::vector<uint8_t> whd_sides;@@ -2883,8 +2905,11 @@ std::vector<int> convert_segs(wad &wad, lump &lump, const std::vector<int>& linerc.push_back(newdata.size());auto ms = get_field_inc<mapseg_t>(lump.data, offset);uint16_t l = linedef_mapping[ms.linedef];- assert(ms.v1 < 2048);- assert(ms.v2 < 2048);+ // (a big level's vertexes from 2048 on: the top bit of the line says their top bits follow the seg)+ if (l >= 32768) fail("a level with more than 32767 bytes of lines\n");+ if ((uint16_t) ms.v1 >= 32768 || (uint16_t) ms.v2 >= 32768) fail("a level with more than 32767 vertexes\n");+ bool high = (uint16_t) ms.v1 >= 2048 || (uint16_t) ms.v2 >= 2048;+ if (high) l |= 0x8000;assert(ms.side == 0 || ms.side == 1);newdata.push_back(ms.side << 7 | ((ms.offset != 0) << 6) | ((ms.v2 >> 5)&0x38) | ((ms.v1 >> 8)&0x7));newdata.push_back(ms.v1 & 0xff);@@ -2906,18 +2931,20 @@ std::vector<int> convert_segs(wad &wad, lump &lump, const std::vector<int>& linenewdata.push_back(ms.angle & 0xff);newdata.push_back((ms.angle >> 8) & 0xff);}+ if (high) newdata.push_back((((uint16_t) ms.v1 >> 11) & 15) | ((((uint16_t) ms.v2 >> 11) & 15) << 4));}offset = 0;int pos = 0;for (int i = 0; i < count; i++) {auto ms = get_field_inc<mapseg_t>(lump.data, offset);uint16_t l = newdata[pos+3] + (newdata[pos+4] << 8);+ bool high = l & 0x8000;+ l &= 0x7fff;assert(l == linedef_mapping[ms.linedef]);assert((newdata[pos] >> 7) == ms.side);uint16_t v1 = newdata[pos+1] | ((newdata[pos]&7)<<8);uint16_t v2 = newdata[pos+2] | ((newdata[pos]&0x38)<<5);- assert(v1 == ms.v1);- assert(v2 == ms.v2);+ int seg_start = pos;short soffset = 0;if (newdata[pos] & 64) {if (newdata[pos+5] < 128) {@@ -2935,6 +2962,14 @@ std::vector<int> convert_segs(wad &wad, lump &lump, const std::vector<int>& lineassert((short)(newdata[pos] | (newdata[pos + 1] << 8)) == ms.angle);pos += 2;}+ if (high) {+ v1 |= (newdata[pos] & 15) << 11;+ v2 |= (newdata[pos] >> 4) << 11;+ pos++;+ }+ (void) seg_start;+ assert(v1 == (uint16_t) ms.v1);+ assert(v2 == (uint16_t) ms.v2);}rc.push_back(newdata.size()); // we need an end marker too}@@ -3093,6 +3128,14 @@ void convert_nodes(wad &wad, lump &lump) {} else {h = (16 * (mnode.bbox[s][BOXTOP] - bdash) - 1) / (bbox[BOXTOP] - bdash);}+ // (a child with no height or width: the smallest box from its corner, not one of -1 sixteenths)+ if (w < 0) {+ w = 0;+ rdash = ldash + (bbox[BOXRIGHT] - ldash) / 16;+ }+ if (h < 0) {+ h = 0;+ }int tdash = bdash + ((bbox[BOXTOP] - bdash) * (1 + h)) / 16;if (l < 0 || l > 15 || b < 0 || b > 15 || w < 0 || w > 15 || h < 0 || h >> 15) {fail("Bad bounding box conversion %d.%d %d->%d,%d->%d becomes %d->%d,%d->%d, but lwbh is %d,%d %d,%d\n",