Taking on a big project alone is tricky. I can spend an hour or two per night working on the train game and it takes me a week to make any real progress. I also have spent a few weekend days working all day but that’s because I’m planning and designing it as I go and a lot of the coding is by experimentation.

I’ve got the coupling and decoupling working well at the moment. All of the issues are resolved so that the train stops before hitting a string of cars and detects that it needs to pick them up. I can drop off some cars, move others, and go back and pick up the ones I dropped off earlier. It’s all fun, and slow, to watch.

I am stuck at the moment trying to decide how to handle the situation where the train is on a waypoint and needs to move to another waypoint that is also somewhere under the train. How do I pick which direction to go if the train on stopped on a waypoint and needs to stop before the other? The train clearly needs to “back up” but which direction would that be? My decision will be to use the direction from one waypoint to the other to use as the train direction and move to the appropriate location based on that.

Subject change
Yeah. I just plugged in a new Logitech solar keyboard. It’s 10lbs lighter and 3 feet thinner than the keyboard I was using before. This one doesn’t have the letter rubbed off of important keys but it’s got a very different feel. Woo hoo!
Subject change back

Once I get the overlapping waypoint issue resolved, I have one more thing that I know about that is broke. If a train is added to the game and that train won’t fit properly on its first waypoint, the game will crash. I need to start at one end of the train or the other and place the train that way. I only need to move from one car to the next until I get to the pivot on the locomotive and then I can set the train location and the rest of the code should work fine.

I can’t ever take the train length and use it as a means of placing the train on the track or even when stopping before or after a waypoint because the train is actually longer on curves than on straight track. Let me explain; train cars don’t bend around curves, they form a cord of the arc on which they sit. This makes the curved distance from one end of the car to the other longer than the straight line distance.

ontrack.jpg

Notice in the picture above that the rectangular train car is sitting in a position on the very sharp curve in such a way that the very center of the car is not even close to the center line of the track. The distance from the front wheels of the car to the rear wheels is always the same but the distance around the curve is longer for smaller curves. The code correctly places the cars on the track although it also takes a few shortcuts for calculating the distance from one car to the next because real train cars have couplers that are mounted to the very ends of the cars where they are not lined up with the center line of the track where they pivot.

I need to do some experimentation to see if a sharp curve can cause my existing code to cause problems when passing waypoints but I think it will be fine. This issue will certainly keep me from calculating the location of the train at the end of the track without starting from the end of the train that is otherwise going to be off the end of the track. Or I’ll just add a fudge factor and fake it.

Once I’ve got things working consistently, I need to test for odd behaviors. I know that it’s possible to connect track together in a way that exposes a bug in the track code. I just don’t know how to reproduce it yet.

Oh, here is a movie that you can download and watch of the train doing a few things. I show and hide the train route a few times during the playback but it’s otherwise just the train dropping off and picking up a few cars. The switchback operation is automatic. The video is big and it’s an avi file so I’m not sure how it will play for you in your browser:


Launch in external player