Logs / Route 012

Late September: the car moved to C++

Every car on the island now runs its physics in C++, and the script version has been deleted. Also a sea that takes its shape from the wind, helicopters that hold their height, ground with some depth to it, and trailers switched off.

·8 min read·9 sections

Four of the sports cars nose to nose, in an August build

The September log went up on the 25th. Another 377 commits have gone in since, in three days, and most of them went into one job: taking the car’s physics out of Godot’s scripting language for good.

The car runs on C++ now

Since the afternoon of 25 September, every car on the island runs its physics in native C++, the one you’re driving included. AI traffic went first. Everything else followed after a test drive, and the commit that flipped the switch quotes the verdict: “seems to drive great … flip on native by default”.

A week earlier the whole port had been called off. The first plan moved the tyre’s busiest blocks of maths to C++ one at a time, and on 17 September three separate measurements said it was saving next to nothing. One of them took out a third of the work the port was supposed to save, and the timings didn’t move. The note that stopped the port reads: “Predicted ~9 µs. Delivered nothing.”

The maths had never been the expensive part. Moving values in and out of the script objects was. The design note written the next day puts it in one line: “A car’s physics is expensive because of GDScript data access, not because of its maths.” So the second attempt moved the whole physics step in one piece, along with every bit of state it reads.

Identical, until it wasn’t

The rule for the port was that the C++ car had to match the script car bit for bit, with no tolerance at all. A fleet of 16 AI cars ran both versions side by side and compared every output on every tick. The first time all the parts ran together as one car, there were 61,561 mismatches. It took 13 rounds of fixes to get that to zero.

By 26 September six vehicles had passed, four cars and two trucks, and that day the rule was dropped for everything left. The rest of the fleet went over without it, and then the script versions of the engine, gearbox, clutch, differential, suspension, steering, brakes and tyres were deleted. Counting the test suites and tools that only existed to compare the two, that’s about 126,000 lines of script deleted in two days, and the game code itself came out about 19,500 lines lighter. All 34 cars and 3 trucks run the C++ model now. There’s nothing left to fall back to.

Is it faster? Piece by piece, by a lot. Measured on its own, the C++ engine runs about 80 times faster than the script one, and the tyre about 13 times. A whole car hasn’t been timed. On 26 September a note in the project reads “the cpu usage didn’t really go down”, which was put down to the glue code still running between the two halves. Most of that glue came out the same night. Nobody has measured since.

175 things that looked wrong

Porting a physics model line by line means reading every line of it. Anything that looked wrong went into a register instead of being fixed on the spot, because a fix would have broken the bit-for-bit match. By the end it had 175 entries. A gearbox swap for a part of exactly the same weight made one car 90 kg heavier. An electric car with someone in the driver’s seat had no reverse. An electric car in mid-air regenerated, braked its wheels and charged its battery. The burnout signals, in the register’s own words, “can never fire”. And one test saved to the real settings file instead of a scratch copy, and on 19 September cut the developer’s settings down to 15 keys, with no backup.

106 of them are fixed now, and 19 turned out to be dead code and got deleted. 33 are still open. Most fixes that would change how a car feels are built but switched off until someone drives them, under the heading “build variants now, drive later”.

The drift assist went too. It was off by default, and of the presets only Cinematic switched it on. The ruling that removed it calls it “a legacy feature”.

Trailers are off

One casualty. Trailers don’t fit the new model, so they’re switched off entirely: they can’t be spawned or hitched. The decision reads “Skip trailers, they need to be rewritten from scratch anyway.” The last log said trailers were next. They still are, from a bit further back.

The sea takes its shape from the wind

The sea got most of 28 September to itself, and it’s still being tuned. The biggest change is that its shape now comes from the wind. A light breeze makes short, choppy waves, longer ones build in from about 8 m/s, and a background swell keeps going even in a calm. Wave trains cross each other at an angle instead of all marching the same way. Whitecaps need steep, tall faces now: they start at about 6 m/s of wind and cover the sea by 11. Above 6.5 m/s the crests throw spray. In light air, glassy slicks run downwind, and from 6 m/s long streaks line up along the wind. Clear weather blows about 2 m/s and a storm 6 to 14, so most of this only turns up when the weather does. How the weather gets there is in its own log.

Up close, the island, the piers and the boats reflect in the water, where until this week nothing in the scene could. Looking down through the water, the seabed bends the way it should instead of smearing sideways at shallow angles. Light coming through a wave face makes the crest glow. On the shallow seabed the caustics sway with the waves overhead and split into faint rainbow edges. And waves climb the beach now. Before, every wave went flat at the waterline, whatever the weather.

Two fixes from the same day earned their commit messages. The foam’s drift was fed a position where it wanted a speed, so it sped up the longer the game ran: “fine at spawn, a fast film after minutes, a blur after ten.” And the new water shaders had passed every automated check, because those checks only parse a shader. They didn’t compile on an actual graphics card, and the fix is titled “shaders now actually compile in a live renderer”.

Helicopters that hold their height

The helicopter controls got a revision. The collective has two modes now, switched in flight with K. Climb rate is still the default, with the keys asking for up to 4 m/s up or down, and direct moves the blade pitch itself. Altitude hold is on by default: let go and it captures the height, then flies back to it at half a metre per second for every metre it’s off, up to 4 m/s. It holds height above the sea, not above the ground, so it won’t climb for a hill.

The pedals ask for a turn rate now, 60° a second by default (anywhere from 15 to 120 in the settings), and brake the turn when released. On a gamepad the triggers are the pedals and the bumpers work the collective. All three helicopters got a cockpit camera. And the hitch at the first helicopter of a session is gone: its twelve synthesised sounds took about a quarter of a second to build, and now load from disk in about a millisecond.

Ground with some depth

All 26 ground types, from asphalt and black sand to coral and bog, now use parallax mapping. Stones and cobbles look raised and shift as the view moves, and cast small shadows away from the sun. At night they follow the moon now. Until this week they aimed at a light that goes dark at dusk. The depth runs from 1.5 cm on concrete to 10 cm on a boulder beach, and fades out between 2 and 7.5 m from the camera, so it’s something to notice on foot more than from the driver’s seat.

Midday looks less flat as well. Between nine in the morning and six in the evening the island had an oddly even look, for two reasons. The large-scale colour variation across the ground was switched on with both of its tints set to white, so it did nothing. And ground textures stopped blending into each other at about 1.2 km, which left hard, stepped edges further out. The ground now drifts between warm and dry and cool and damp in patches a couple of hundred metres across, and the blending reaches about 4.8 km, past the point where the fog takes over anyway.

Grass on your tyres

Spin a wheel or slide through grass and it throws clippings, in the colour of whatever is growing underneath. The wheel has to be sliding or spinning against the ground at 1.5 m/s or more, and roads don’t count.

The grass draws further, to 160 m on high and 220 m on ultra, with blade shadows out to 30 and 40 m. Getting there turned up a better story. The blade shadows were meant to come from the engine’s new contact shadows, which worked in the editor and drew nothing in the game. One setting behind them turned out to be a quality mode from 0 to 2 that the game had been treating as a length, and the ultra tier set it to 3. The out-of-range value broke the whole pass and took that frame’s grass with it. With the value fixed, the contact shadows still didn’t appear in a running game, so they’re parked behind a switch and the older shadows are back. The same evening, zero wind started meaning still grass. A calm field had been swaying slightly all along.

Smaller things

Electric cars can reverse again with someone in them. Their gearboxes started in a mode the reverse key doesn’t work in. The red and amber cat’s eyes are back on the roads, after loading invisible. Weather fog no longer disappears now and then while you drive and comes back later. Stripping a stock part off a car in the garage takes its weight off too. And a turbocharged car’s whistle cost 0.44 ms a frame to synthesise, 42% of which went on rendering silence. It now renders at half the sample rate and skips the silent stretches, so an idling turbo costs nothing.

Filed under update, physics, helicopters, hachijo-jima

Photo mode1 / 1