Foundational model complete


After declaring bankruptcy on the flightmodel in what you saw last time, I put together the visual/physical side of the simulator in rust using softbuffer, meaning it's a rasterized software engine, which has been fun and I'm enjoying the un-antialiased graphics and retro vibe. I built a map of San Francisco bay as well as three more-detailed airports, SFO, OAK and NGZ (Alameda).

That worked great but suddenly I was having periodic performance issues. I went round-and-round with this and finally tracked it down to the geometry of my line algorithm trying to decide if it was in frame or not, at certain angles, particularly when banking, occasionally lines would appear to the algorithm to be nearly infinitely long, causing a slowdown where I went from 60fps to 3fps to 1 to 20 seconds per frame and then it would "unstick" and jump back to 60fps like nothing happened. I solved the problem with frustrum culling, which basically is an async task that runs at ~15fps and culls the scene to a viewbox about 2x larger than you can see. That way there's enough geometry if you're rapidly turning or whatever, and even though it's a sorta expensive operation for a software renderer, it only needs to do it every 4 frames and it's happening async. Probably a lot of optimization left to be done there but it fits well inside my frame budget.

After I solved for that, I took my "flat earth simulator" which runs in x,y,z mode and mapped the position to very accurate lat/long. When the plane reaches a couple of km out, it resets the plane's position to 0,0 and keeps the lat/long, and then calculates the offsets for the scenery geometry and draws them with the appropriate x,y offsets. This along with some magic allows you to fly intercontinental routes and trans-oceanic paths, with realistic directional drift if you simply hold the same heading.

Of course, you can't test this without some kind of autopilot. So I put together an altitude hold and a heading hold that call the user control functions, so it's still flying the plane, it's not on rails or anything. So then it could in theory cross oceans. Then I added waypoint support, which is simple lat long alt format. This uncovered a bunch of bugs in my XYZ ENU ECEF mapping between coordinate systems, both with directional physics and scene drawing logic. After much gnashing of teeth, waypoint support worked with a local course doing things like 2nm north, 2nm nw, 2nm E, 3nm SE, 20 miles S, 20 miles N etc etc. Next up I had it run a course from SFO, through my 11 waypoint mission, then fly to OAK (E), then to Napa (N), then to Stockton (SE), and then north to Sacramento (45 miles NNW) and SMF (Sacramento) airport. This was about 130 miles of flying. For grins I had it go to SEA sea-tac airport in Seattle which added another 550 miles or so. It handled this with ease, with the seatac "target" waypoint scenery drawing exactly where I expected it to. Honestly I was surprised it worked at all, particularly without crashing.

That evening I found flight JAL1, Japan Airlines flight 1, I guess recently they've been having storms up by alaska so they've been flying a pretty "flat" route between SFO and Tokyo, but last monday they flew a route that uses checkpoints that looks more like a normal great circle route, so I used that one. I quickly added some position logging logic, and position drawing function so I could visually track what the plane was doing. After that I plugged the ~16 waypoints into the system and flew the mission from SFO to Tokyo HND and it took about 15 hours at 325 knots but it flew the whole route and indicated ground speed seems to match up exactly with real world given distance to target etc. As a sanity check, I plugged the waypoints into Google Earth, then took a screenshot of it and plugged the screenshot into MS Paint and connected the dots. The output looked exactly the same as my position drawing! Amazing. Everything is working. Nothing crashed, no errors at all. It drew Tokyo waypoint on the ground exactly where I was expecting it to.

Next up is to clean up some of the scenery, in the "move fast and break things" phase, I created some cool scenery but it got exported wrong or flipped, or I created scenery but it never exported correctly because I skipped a step. So I want to get the scenery rendering pipeline done and correct, re-export everything with the correct origin point, add a couple of landmarks (transamerica building, salesforce tower, ferry building, gg bridge, bay bridge, hunters point crane).

At that point I can call it "done" and release v1.0.0. In my opinion people are too shy about releasing versions, this is a fully functional flight sim with real physics lift/drag/thrust/gravity and basic scenery, waypoint missions autopilot etc. This is a good stopping point for what I set out to accomplish.

Leave a comment

Log in with itch.io to leave a comment.