Developer Diary #4: Traffic Anarchy

Today I decided to start making use of my lane overlap detection and made cars aware of overlaps.

Before tackling higher-level traffic rules like right-before-left, yielding or traffic lights, it was important to just get basic collision avoidance going (because you will need it if the higher level rules fail to do their job).

This was my first result:

gif1

(Sorry for the low-fps GIFs, they are the quickest to produce)

You can see cars on the intersection noticing each other (yellow dots) and using the overlap data to find the place where to stop in order to avoid crashing into other cars (red dots).

It's quite interesting to see that giving cars just this basic collision advoidance results in barbaric but kinda fair "whoever comes first, goes first" traffic patterns.

There was still a bug in the calculation, causing some crashes to still occur (because one car wrongly assumed that the other one already left the overlap).

After fixing that, the behaviour became even more stable - cars could even somewhat reasonably handle this chaotic situation:

gif2

For low speeds it already worked really well, but for high speeds there was the problem that cars only started to care about overlaps once they entered the intersection, which was often too late.

So the last thing I worked on today was to make cars think about overlaps even before, when approaching an intersection. It is unfnished, because I have to sleep now, but this is its current state:

gif3

(Dark red dots show stopping location determined before even entering the intersection. They seem to be correct, but for some reason, cars don't appropriately slow down yet, only once they enter the intersection)

Two small asides:

a) for people who worry about performance of such detailed simulation, it is important to realize that only the very first cars in each lane have to do this slightly complicated obstacle detection. But even for them, most of the work has already be done by figuring out the overlap intervals beforehand. All that needs to be done is some lookup and simple mapping of car positions from one lane to another.

Note: all that the other cars have to do is stupidly follow the vehicle in front of them and not crash into it. Their next-vehicle-ahead changes very infrequently!

b) I really noticed that the reimplementation of the road system starts to pay off. With the old road system I worked on the same problem for at least a week and didn't get as far. Today: just one day!

That's all! I hope you enjoyed it, see you soon!


Discussion on Reddit
Discussion on Simtropolis
Discussion on Something Awful


Want to be notified when there's development news? Subscribe to the Newsletter!

You can also follow @CityboundSim on Twitter

If you want, you can already show your support. Any amount is highly appreciated!

Bitcoin address: 1KQR42DR9UP7WGrS98fcTpkgYPYxqwMZeu
Dogecoin address: DPkZosjgtAFnbXtDgauUJnyiPacfr8SLbz

Developer Diary #3: The Struggle

Last time, I thought that there was not much missing until lane overlaps would work properly.

Boy was I wrong!

I have a collection of screenshots on my desktop, telling the story of my efforts today and yesterday. Let me share it with you.

Having almost lost hope of finding a solution to my problems the day before, I decided to tell Michael about it, as the first thing to do today.

First I showed him all the lanes that exist on an intersection - it is their overlap intervals that I wanted to find:

screenshot1

For debug purposes, I decided to show the detected overlap intervals on top of that, orange being merging overlaps, red being head-on overlaps:

screenshot2

As can be seen, some overlaps that should have been detected are completely missing (see white sections where there should be merging overlaps). Also the red, head-on overlaps were much too long. They started at the right point, but went on for too long.

Also in many places, overlaps could ...well... overlap - basically an overlap with one lane started inside an overlap with another lane. But because they had the same color, it looked like it was just one continous overlap.

(I'm not sure if you can follow me here...)

Michael had the great idea of vertically distributing the colored lines for each overlap, so you could see their actual lengths, even if they were on top of each other.

He also suggested to make the lane shapes that are tested for overlaps thinner than the lanes visually were, resulting in hopefully smaller and more understandable overlap intervals.

I did that and first just gave each unique overlap on the intersection its own height, resulting in this extremely unhelpful image:

screenshot3

Then, after giving only overlaps of the same lane different heights, it became more understandable:

screenshot4

If you look closely at the red overlaps, you can see that they start at the right place, but go on until the end of the intersection.

Simplyfing things further, I disabled overlap tests for all lanes but the innermost ones, making everything even clearer:

screenshot5

After nearly going mad for the first time, I discovered that the overlap intervals were actually completely fine, but there was a bug in the code that drew their colored lines!

screenshot6

Much better! (the perspective warps everything bit)

So I decided to make everything flat and try a full intersection with all lanes again:

screenshot7

There was still some weird stuff going on with merging overlaps - some were just missing, others mutated into these strange red circle-arcs.

The latter was easily fixed, the first, however almost drove me mad a second time, over the course of some additional hours.

In the end it turned out to be due to a beginner-level programming error that I made somewhere, as is the case so often :)

screenshot8

Beautiful. Everything is there.
To celebrate that some more, here is a slightly higher-res picture of a normal intersection next to one with a one-way road:

screenshot9

I hope you enjoyed this, see you soon! :)

Edit: after looking at these pictures some more, I noticed that there are in fact still some missing merging overlaps. Back to work...

Edit 2: turned out to just be a display bug again. Now really everything is there!


Discussion on Reddit
Discussion on Simtropolis
Discussion on Something Awful


Want to be notified when there's development news? Subscribe to the Newsletter!

You can also follow @CityboundSim on Twitter

If you want, you can already show your support. Any amount is highly appreciated!

Bitcoin address: 1KQR42DR9UP7WGrS98fcTpkgYPYxqwMZeu
Dogecoin address: DPkZosjgtAFnbXtDgauUJnyiPacfr8SLbz

Developer Diary #2: Intersection soup

Since last time, I managed to make cars follow multisegment roads properly!

multisegment cars

One interesting problem was that cars suddenly sped up and slowed down in narrow corners, since their linear progress on a lane bundle segment was measured just relative to the lane bundle center line. On the outermost lanes of roads this was particularly noticeable.

So I created all kinds of geometry code to convert between lengths and offsets on different adjacent lanes - and made sure that car progress and velocity were always measured relative to the lane they were actually on.

All of that works now.

Then, I started working on detecting lane overlaps on intersections - something that I already implemented once for the old road system.

After getting stuck on a bug that was entirely due to me forgetting about Javascript's function-only-scope, I got a first version of overlap detection going. I just displayed the starts of overlaps in red and ends of overlaps in green:

stupid overlaps

So clear what's happening!

But seriously, it looked kinda fine at that stage.

I wanted to make sure however, so I implemented a module for displaying arbitrary paths for debug purposes.

This time, connections on the intersection are drawn as white lines, merging overlaps in orange, crossing overlaps in red:

line overlaps

Well, still kinda a little bit broken, turns out!

And that's where I had to stop today, since it is late night now and I should get sleep :)

Let me know what you think!


Discussion on Reddit
Discussion on Simtropolis
Discussion on Something Awful


Want to be notified when there's development news? Subscribe to the Newsletter!

You can also follow @CityboundSim on Twitter

If you want, you can already show your support. Any amount is highly appreciated!

Bitcoin address: 1KQR42DR9UP7WGrS98fcTpkgYPYxqwMZeu
Dogecoin address: DPkZosjgtAFnbXtDgauUJnyiPacfr8SLbz

Developer Diary #1: Where do you think you're going?

Finally a little progress that is literally visible!
Cars now kinda started working on the new roads.
(As you can see, not completely, more soon!)

To give you an idea why it took so long to get here, here is a short description of the deep underlying differences between the old and the new road system:

Old:

  • smallest entity: lane piece (just one straight or curved segment)
    • adjacent pieces were treated like completely separate ones
  • cars were managed on a per-lane-piece-level!
  • roads were collections of a lot of lane pieces
  • intersections consisted of even more lane pieces!!
  • the code for multilane and intersection traffic had no chance but to be horrible, for each car you needed to constantly consider at a lot of cars on other lane pieces
    • forking and merging lanes were something fundamentally different from intersections
    • resulted lots of "special cases" that are actually just duplicates of each other, but couldn't be simplified as such
  • connections between lane pieces were given implicitly
    • relation descriptions between lane pieces, like "left", "right", "next", "previous
    • hard to create
    • hard to update
  • finding conflicts between lane pieces for intersection behaviour was hard, ignoring false positives was even harder!
    • on intersections, a car basically saw every other car as a stationary, crossing obstacle, even the one in front of it on the same lane, in the worst cases even itself!
    • avoiding this was impossibly hard to implement, one of the main inspirations for a redesign of the system

New:

  • smallest entity: lane bundle
    • represents multiple lanes next to each other
    • can have a complicated multisegment shape, but still functions as the continous stretch of road that it actually is
  • cars are managed on a per-lane-bundle-level
  • this means it is a lot easier to do multilane traffic: all the relevant cars are probably on the same lane bundle
  • roads consist of just one or two lane bundles (one, or two-way road)
  • intersections still consist of many lane bundles
    • but because each can have a complex shape (which is often required for properly connecting the roads that enter an intersection) and still be one functional unit, it is much easier to avoid these false positive self-collisions I described earlier
  • shape information needs to be stored only once per lane bundle, the graphics card takes care of rendering cars in the correct position according to car's progress on the lane bundle and its lane offset
    • especially wide multilane roads, or long roads with a complicated shape benefit from this
  • connections between lane bundles are given explicitly by so called "connection points"
    • easy to create, easy to update, easy to manage
    • easy to visualize and make usable for the player (more on this soon)

I'm already tired and I probably forgot a lot of stuff, or wrote it in an incohesive way, but I hope this first developer diary was interesting.

Let me know what you think!


Discussion on Reddit
Discussion on Simtropolis
Discussion on Something Awful


Want to be notified when there's development news? Subscribe to the Newsletter!

You can also follow @CityboundSim on Twitter

If you want, you can already show your support. Any amount is highly appreciated!

Bitcoin address: 1KQR42DR9UP7WGrS98fcTpkgYPYxqwMZeu
Dogecoin address: DPkZosjgtAFnbXtDgauUJnyiPacfr8SLbz

2014 in Review

This year was... exciting!


Discussion on Reddit
Discussion on Simtropolis
Discussion on Something Awful


Want to be notified when there's development news? Subscribe to the Newsletter!

You can also follow @CityboundSim on Twitter

If you want, you can already show your support. Any amount is highly appreciated!

Bitcoin address: 1KQR42DR9UP7WGrS98fcTpkgYPYxqwMZeu
Dogecoin address: DPkZosjgtAFnbXtDgauUJnyiPacfr8SLbz

The Road to Alpha, Week 40 - Hyper-Active

I wouldn't mind if things calmed down a little :)


What I did

  • Implemented basic version of
    • automatic intersections
    • road markings

What I will probably do next

  • Make cars go again on the new roads

Discussion on Reddit
Discussion on Simtropolis
Discussion on Something Awful


Want to be notified when there's development news? Subscribe to the Newsletter!

You can also follow @CityboundSim on Twitter

If you want, you can already show your support. Any amount is highly appreciated!

Bitcoin address: 1KQR42DR9UP7WGrS98fcTpkgYPYxqwMZeu
Dogecoin address: DPkZosjgtAFnbXtDgauUJnyiPacfr8SLbz