But the same effect is not working here in my city. I’d looked at a lot of reference pictures where the streets were pure black, and only streetlights and car lights were visible. I pull back and assess the view now that all of the key details are in place, and I’m not happy with the result. Still I’m going to take a wild guess and say I have perhaps three or four hours left before I hit my 30 hour goal. Weekends do that, particularly since I had a lot of Left 4 Dead mixed in with the coding hours. (Although I’ve lost track of how many hours I’ve sunk into it. (An hour and a half is about 5% of my budget, assuming I stick to it. Then again, I might have incurred the worse losses as a percentage of total budget. Luckily for me, my losses were only a bit over an hour. They scrapped the audio simulation and replaced it with more conventional videogame sound behavior. It was actually easier to have artists manually specify how things ought to sound and how far particular sounds could travel than to have the game try to intuit it. In the end, the result was worse than the simplistic system it was supposed to replace. It was supposed to make big rooms echo, dampen sounds in other areas, and so on. The relevant passage is about halfway down.) During development of Doom 3, they had a programmer write a complex audio / acoustics engine that would try to propagate sounds realistically.
![trap street lights graphics trap street lights graphics](https://cdns-images.dzcdn.net/images/cover/06a57e695984aa4162c1c3cc5fb7dc17/500x500.jpg)
John Carmack talked about this at Quakecon in 2004. The programmer (me, in this case) sits down and thinks “oooh! I know how this system works, so I’ll write a simulation of it!” It’s a deadly trap, because once you start simulating one thing (cars changing lanes) then you suddenly need to simulate other things (making visually believable lane-changing movements for automobiles) which requires still other things (turning behavior of a car) and pretty soon you’re coding some sort of time-devouring boondoggle when all you wanted was to write a few simple rules about going around slow people. This is a classic case of oversimulation.
![trap street lights graphics trap street lights graphics](https://cdn.vox-cdn.com/thumbor/FfWqmjH-1cMzKhN5Cx8XJtlbzTU=/0x0:3000x2000/1200x0/filters:focal(0x0:3000x2000):no_upscale()/cdn.vox-cdn.com/uploads/chorus_asset/file/20789883/GettyImages_1227785440.jpg)
#Trap street lights graphics code#
So… I wasted a bunch of time writing code that slowed down the program and looked terrible when you noticed it at all. It was small and simple, but multiplied by hundreds and hundreds of cars it was causing a measurable performance hit. Worse, the tiny bit of AI I’d written was slowing the program down. This is aside from the fact that steering with the front wheels produces some fairly noticeable differences between the movement of headlights and taillights. Cars decelerate before the turn, increase the rate of turn as they go, and begin to accelerate again before the turn is completed. Both turns and lane changes actions are very complex. On the rare occasions where I was looking when a car made a turn, the robotic movement actually hurt the verisimilitude of the scene instead of helping. It was actually hard to spot a car doing something interesting. Then I pulled back to the city-wide view and found that all that work was almost completely unnoticeable. It was still a little stiff, but I was confident that with a bit more tuning I could make it work. I spent over an hour fussing with a couple of intersections and tuning the car behavior to make lane changes and cornering look natural. So I wrote a bunch of code to have them switch lanes if they find themselves behind a dawdler, and randomly make turns when they come to an intersection. I thought it might be cool to have the cars engage in more elaborate behavior. This would look crazy if you were looking straight down on the scene, but up here in the News 5 chopper it looks okay. If the car is heading away, it draws it red, otherwise, white. The program draws a simple 2d panel at a car’s location. They then select a speed and drive in a straight line until they get to the edge of the map, and then they randomly appear in a new location and repeat the process. Since I have the lanes defined, I can just drop cars randomly onto lanes and let them figure out which way to go. Naturally enabling it causes a performance hit, but I can’t really appraise how bad it is until I get some of the more egregious slowdowns fixed and the overall performance optimized. I don’t want to embrace or discard the feature, so I make it so the effect can be toggled off and on.
![trap street lights graphics trap street lights graphics](https://cdn.dribbble.com/users/38169/screenshots/14555805/media/e29a77da176024eaae6541db02e61f0a.jpg)
The effect is of course striking, but unrealistic. I add another render pass for doing bloom lighting.
![trap street lights graphics trap street lights graphics](https://wallup.net/wp-content/uploads/2017/11/23/496958-Tokyo-filter-photography.jpg)
That done, I can have it scan over the world and look for places that need streetlights. In an earlier step I reserved street space, but now I’ll take that space and divide it up into sidewalks and specific lanes. But in order to place the streetlights, I need to know where the streets are. Now it’s time to round out the scene with lights.