The short answer is: to save memory.

The cars and replay seem to be a case of damned-if-we-do, damned-if-we-don’t. If we don’t stop the cars and reverse them in replay, we get piles of bug reports. If we do try to replay the traffic, we get bug reports too.

The current implementation is a bit strange: when you replay traffic, the cars will go back a bit in time, but at some point they will just stop and refuse to reverse any more. What’s going on?

The answer is that the cars have the memory of a goldfish. They simply don’t remember where they came from. Each car knows what “link” it is on, and about when it got onto that link and how fast it is going. (A link is a single straight piece of road.) So when we go into replay, we can easily move the cars along their links as time goes forward and backward.

But when we reach a time earlier than when the car entered the current link, the car has know idea how it got there, so it is forced to stop.

This is a simple case of not wanting to burn four tons of memory on a feature that is mainly visual. To replay the cars, we would have to accumulate a history of every link a car has been on as it drives. For 20,000 cars and a sim that’s been running a while, that’s a lot of memory to burn just in case you happen to hit the replay button.

In fact it gets worse. The cars are kept in a data structure that tells us who needs to make a driving decision and when.* This structure is optimized for the cars moving forward in time. We’d have to make and maintain an entire second copy of this structure to move the cars backward; again burning CPU and memory while you fly just in case you might hit a replay.

So instead we just provide replay on the current link.

* Programming nerds: the cars are in a priority queue by time to next navigation decision. I consider this to be very clever.

About Ben Supnik

Ben is a software engineer who works on X-Plane; he spends most of his days drinking coffee and swearing at the computer -- sometimes at the same time.

8 comments on “Why Don’t the Cars Work Quite Right in Replay?

  1. Why do you even bother to give cars replay capability?

    IMHO a few notice and even less complain when the cars are not set back.

    The place where it would be noticed is on airports which have all kinds of utility vehicles running around.

  2. Point taken.

    But I still want to nag you a bit 🙂

    In the current implementation of the cars you have "goldfish memory" issue, with the visual anomaly of the halted cars, whereas if you'd implement no back tracing capability in cars you could simply say it's a feature, no bug. Still people would complain, but I imagine thats what people do.

    I view cars as (essential) visual fluff, like the smoke particles from the smokestacks, or background noise. I looks like you created yourself a problem where there shouldn't be one. However I do not implement multi platform flightsims for a living so I am hardly an expert, just an interested bystander.

    Steven.

  3. You're going to have to trust that we picked the path of least total abuse by users, which, as you have demonstrated, is _not_ the path of _no_ abuse by users. 🙂 🙂

    One more key point: replay and pause in the sim are inherently tied together…so no replay also means no pause, which _really_ makes people crazy. That is, they hit pause and stuff is still "going".

  4. Oh, I'm still in the unabused happy campers comfort zone. I never noticed the halted cars. I will now and start annoy myself tremendously when I see it… 😉

    About the priority queue, I suspect you use the (speed*time) as the priority value? This way you can pop the cars that need to be "transferred" to next stretch of the road more easily from the list.

  5. I'd guess the priority value is the time when the car will reach the end of its stretch. Just put all your cars in the structure, and look at the head of the structure to see if any need to do stuff.

  6. Can't cars be made independent from replay mode? As in generated and moved like in a normal flight. I guess you must have considered that already.

  7. Why remembering the original navigation decisions? If you're rewinding, all you should have to do is drive forward the standard algorithm, but on the left lane, and with the car objects reversed! UK would be different… 🙂

    (easier to say than to implement I guess, but just in case…)

Comments are closed.