it's the vibe

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

I stumbled across an old video of this, and was quite impressed actually.

I thought I'd revive the code and get it building again.  And then I thought I'd use this as a test project for "vibe coding"; that is, using an AI to do most/all the work. I will say that "vibe coding" is not coding at all. It's more like guided direction - and requires little skill.

Nonetheless, the results are impressive. If I continue with this project it will be with AI coding, although the original engine was totally hand-written (from scratch) by yours truly. Already Claude AI has found significant improvements in speed and fixed some bugs. There's no going back, I'm afraid.

This is an ELF project, and as such the ARM is doing all the math/calculations. I'm not interested in arguing if this is an "Atari 2600" game or not. It runs on hardware - that's my criteria. Expect me to be savage on anyone trying to divert/distract by arguing otherwise. This is not the place.


Claude's update...
Elite 3D engine — changes and speed improvements

This covers the work on the 3D engine, display and game behaviour since the original single-ship demo. Instruction counts come from the ARMv6-M emulator harness in [tt]bench/[/tt] (see Measuring). Each change was checked there, and the frame budget was later confirmed rock solid on hardware.

Speed: summary

StageInstructionsNotes
Original engine, 1 ship383,163 per update~60% of the time in software float
Fixed-point 3D rewrite104,3793.7× faster
+ incremental orientation, edge clipping100,7993.8× faster
4 ships, before the second round189,518 per update
+ downsample, line drawing, frame merging167,278buffer-swap frame 144,189 → 25,159
+ edge tracing, clip skipping, span fill158,399300 frames byte-identical to before
+ fixed-point flight model144,736float down from 14% to ~4% (the 4% is mostly the harness)

Updates per second matter more on screen than instructions:

ConfigurationFrames per update
Original (1 ship)4
4 ships, one job per frame7
+ merged frames5
+ frame budget, 4 ships, 64 MHz / 168 MHz4.55 / 1.98
6 ships, 80% budget, 64 MHz / 168 MHz5.04 / 2.00

Speed: what changed

3D maths in fixed point
The target (Cortex-M0+, [tt]-march=armv6-m[/tt]) has no FPU, and the original used [tt]float[/tt] throughout, including a Taylor-series sin/cos run for every vertex.

  • Trig: a 65-entry quarter-wave sine table in Q14 (16384 = 1.0) with linear interpolation, and 16-bit binary angles. Accurate everywhere; the old series was 2.6% out at ±π.
  • One rotation matrix per object per frame instead of 6 sin/cos calls per vertex. Scale is folded into the matrix.
  • Each vertex is transformed and projected once, into [tt]transformed[][/tt] and [tt]screen[][/tt]. Before, each vertex was projected 2–4 times, plus again for outlines.
  • Backface culling uses the screen-space sign of the face normal, which matches the orthographic projection.
  • The flight model (positions, waypoints, speed, steering, per-ship perspective) is integer too. Positions carry 4 fractional bits, like transformed vertices.

Rasteriser
  • One polygon filler for triangles and quads ([tt]fillPolygon[/tt]). A quad's diagonal is no longer traced, and its spans are no longer filled twice.
  • Spans are filled a byte at a time, with masks for the partial bytes at each end, across the three colour planes in one pass with running row pointers. The old filler wrote one pixel at a time.
  • Only the rows a polygon touches are cleared in the span tables (all 64 were before), and an unused area calculation is gone.
  • Edge tracing records each row's run once, instead of comparing min/max at every pixel.
  • Clipping: edges and lines are clipped to the screen before Bresenham walks them, and the clip is skipped entirely for edges fully on screen. Outlines and polygon edges share one clipper ([tt]clipEdge[/tt]), so they always agree pixel for pixel.
  • Line drawing steps a byte offset and bit mask instead of recomputing the address for every pixel. It was checked pixel-identical against the old version on 200,000 random lines.
  • Each shared edge is outlined once, using a per-vertex bitmask of edges already drawn (two words, so models can have up to 64 vertices).

Frame pipeline
  • [tt]downsample()[/tt] converts only the 65 rows the kernels read in 3-line ChronoColour, instead of all 192, and uses a 256-entry lookup table: 9× faster (134K → 15K instructions).
  • Frames merged: the ship-movement frame was folded into the first ship's frame, and the dots/cursor frame into the buffer-swap frame, taking an update from 7 frames to 5.

Frame budget: several jobs per frame
The biggest visible gain. After a kernel, the 6507 runs vcsLib's overblank loop from RIOT RAM for 63 scanlines (about 4.0 ms), then waits at [tt]ldx $ffff[/tt] for the ARM. If the ARM's 3D work runs past that, the picture rolls.

  • Work counters: rows filled, edge steps and outline pixels are counted per line or row, so they cost next to nothing.
  • Cost model, fitted against 480 measured renders and accurate to within 7% either way: [tt]cost ≈ 338·faces + 169·rows + 16·edgeSteps + 69·linePixels[/tt].
  • Each frame ([tt]render3D()[/tt] in [tt]elite.cpp[/tt]) runs jobs (the buffer swap, then one ship at a time) while the predicted cost fits the budget. A ship's prediction is its last measured cost plus 12.5%. At least one job always runs, and at most one update finishes per frame.
  • Budget = [tt]clock_kHz × 16 / 10[/tt] instructions: 80% of the 4 ms window, at an assumed 2 cycles per instruction to allow for flash wait states. The clock comes from the firmware ([tt]MP_CLOCK_HZ[/tt]). 60% ([tt]12 / 10[/tt]) was confirmed rock solid on hardware.
  • Motion is frame-rate independent: speeds, turns, jinks, the player's spin and the grow-in are defined per 5 frames ([tt]MOTION_FRAMES[/tt]) and scaled by the frames that actually passed.

SysTick couldn't be used for this: Gopher2600 doesn't emulate it, and the firmware runs ELFs with interrupts disabled. Hence the cost model rather than a timer.

Correctness fixes
  • Anaconda drew half its faces: its face count was hard-coded as 9 where it has 18. Counts now come from the array sizes.
  • Double scaling: objects were scaled once when transformed and again in projection.
  • Face depth accumulated across faces, because the running total was never reset.
  • Object sort: it ran nearest-first, and its result was ignored.
  • Cougar mesh was open: two missing faces left holes, which showed as black.
  • Engine flicker included black, which made the Adder's whole back vanish.
  • Outlines cut into colours: hidden edges were drawn over nearer faces, lines and fills walked edges in different directions, and they clipped differently. All three fixed; outlines now land exactly on fill boundaries.
  • Smaller fixes: dot rendering wrote to the wrong byte, and a hit check compared an [tt]int[/tt] with a [tt]bool[/tt].
  • Player depth: the player ship's size and its sort depth disagreed, so flyers that looked farther away were drawn on top of it. Zoom now moves the ship in depth, so the two match.

Features
  • Ships: 30 models — the 4 hand-made ones plus 26 from Ian Bell's Elite shape file ([tt]doc/B7051600-2.TXT[/tt]), converted by [tt]tools/make_ships.py[/tt]:
    • polygons split to fit 4 corners, with their internal edges not outlined;
    • faces wound to match the file's normals;
    • colours from the file's hues, with Elite's grey shown as white;
    • windows and vents flagged as decals;
    • each model scaled to a radius between 40 and 80 units;
    • the 14 ships with no colour data given fixed baked shading.
  • 6 ships on screen. Ship 0 is the player's; the others fly autonomously toward random waypoints inside the view. Each flyer has its own top speed and agility (65–135%), small random wander, and occasional jinks. Each ship is scaled by its depth (per-object perspective).
  • Orientation: an incrementally updated orientation matrix, kept orthonormal by a Newton-step normalisation (no square root). Drift stayed under 0.0005 over a million frames.
  • Controls:

InputAction
Left / rightMove the cursor
Up / downZoom ship 0
Fire + directionChange ship 0's spin (it keeps spinning at the rate you leave it)
Fire aloneShoot
SELECTShip 0's next model
RESETNext background
Left difficulty switchCycle ChronoColour mode

  • Display: CC, pCC and iCC ChronoColour (as in WenHop Planet Pluto), defaulting to pCC. Six backgrounds ([tt]tools/make_backgrounds.py[/tt]), stored as [tt]const[/tt] in flash, which saved about 4 KB of RAM.
  • Removed: the hit flash and the palette shuffle on hit. Faces always show their model colours, apart from the engine flicker.


Bomberman94

Really amazing and thanks for the good and well structured explanations! May you release a binary for the 2600 - via PlusCart or Harmony?

Propane13

This is so cool!

It makes me wonder what a very low-level Star Fox (from the SNES) would look like on the 2600.  Seems possible with all of these polygons!

Andrew Davie

A couple of hours work with Claude AI.  And my thoughts.

This is the result of a few hours of "vibe coding" using Claude AI on top of an existing (hand-crafted) 3D engine I wrote a few years ago.

To be honest, vibe coding like this makes a mockery of human coding. Anyone who thinks this is "programming" is completely deluded. This is at most asking an AI to follow your "whim" and involves next to no skill. It's sad that we've come to this, but it is what it is.  Sure, the results are fantastic - even incredible - but IMHO this sort of work does not deserve the kind of credit given to REAL programming by REAL humans.

It's great - wonderful - even fantastic. But the people who use these AI engines to create such things are not - for the most part - exhibiting skill and even creativity. It's a shallow husk of both of those things. When anyone can do it just by typing text, the wonder of creativity has essentially disappeared.

Yes, the end result is great, and for some that is all that matters. But what this exercise shows me is that human content and creativity are not only valuable - they must be *priced* as such. Anything I create by hand is going to have to be really expensive to buy from me, just to keep that human value and appreciation "up there".


Andrew Davie

Ships now have laser weapons, choose opponents, and chase and shoot at each other. There are deaths.


Propane13

Those are fair thoughts.

As a 7800 developer, I feel like it's going to get harder and harder to differentiate myself.  New AI-based demos seem to be showing up every day.  And, they look fantastic and make anything I've developed by hand pale in comparison.  I don't want to detract from your work here.  What you've done ie impressive, flashy, and cool.  But, yeah, it's not the same as programming by real humans.

I'm worried that when it gets time for me to sell anything I work on, I'm going to be caught under the flood of games coming out that are ports that everyone has always wanted and simply be dismissed as irrelevant.  That's going to take some effort to figure out a strategy.

It's an interesting pitch to make the hand-drawn things sufficiently expensive.  That's potentially an avenue that could work.  Another thing is an AI disclosure, which might be something the community as a whole may need to figure out (e.g. what level of use).  I may need to think on that.