Built from scratch · C++ Simulation
AirportSim
A terminal airport simulator written in C++17 from scratch, with hand-written queues instead of the STL ones. Below are real runs of the program played back: arrivals hold until a runway frees up, planes low on fuel jump the line, and departures queue on the taxiway and take off while the sun sets. Hover a plane to see its flight.
Pick an airport
Right now
- 0
- Landed
- 0
- Took off
- 0
- Holding
- 0
- Waiting to leave
- 0
- Emergency landings
- 0
- Ran out of fuel
- Tail colour = airline
- Low on fuel
- Emergency, under 20% fuel
- Shadow distance = altitude
Latest events
What the program printed this minute
The animation is drawn from this screen. The C++ simulator was compiled and run with each airport's settings, and every minute's screen was recorded.
What I learned
Every plane in a queue is a node I allocate and delete myself. That means a destructor that clears the list, and no copying, because two queues pointing at the same nodes would delete them twice.
The landing queue is a sorted linked list, so adding a plane is O(n). With a few dozen planes that is fine, and taking the next one is O(1). A heap would be faster on paper and harder to read.
Every minute has to happen in the same order: burn fuel, free runways, then give them to waiting planes. If the order is loose, planes end up in the same place at the same time.