In the last two weeks progress has dramatically decreased. Searching for a job post graduation, working my current internship, and working on my philosophy thesis all contributed to decreased focus on my project. This being noted, progress did not stop completely. In the last two weeks I was able to solve one main issue with TOS, added in a main menu, and began working on a much larger and more interesting track configuration. The large issue that I fixed was an issue to do with knowing when a train was moving through a given section in reverse. My initial thought was that I should perform a search through the sections and test if the various exits to a section change it from moving clockwise to counter-clockwise. I believe that this solution could have been made to work but I quickly realized that a much easier fix was available. The main problem I was facing was knowing if a train was moving through a section in the intended direction. That is to say; should the train be moving from 0 – N or from N – 0? In order to answer that question all I need to know is the direction the train is currently moving and the intended direction of movement through the section. By adding an orientation variable to each section I can simply test if the orientation of the next section matches the turnout direction the train is using to exit the former section, if these match then the train is moving 0 – N, else it is N-0. This solution gets me most of the way but adds one complication; what if a section spans through multiple orientations? Imagine a portion of track which when entered is moving right to left then turns to move from down to up and finally turns again so it is now moving left to right (this section would look like a ‘[‘ or a ‘C’). This type of section would be oriented to the left because the turnout to enter this section heading 0-N is left, the direction of movement is right to left (initially). However, this type of section could also be entered from the left at the top of the section. Entering the ‘C’ from the top right would also use a turnout pointing left and would move right to left but this time we are meant to be moving through the section in reverse, clearly this is an issue. To resolve this I realized that sections could only ever have an orientation in one direction so the ‘C’ would need to break up into three sections, the bottom oriented left, the middle oriented up, and the top oriented right. With this change when entering from the top and heading left we see that the orientation of the top section and the direction of the train are in conflict and so the section in traversed in reverse. The change in sections compelled me also to change how sections are exited. In the ‘C’ example we would not need a full turnout between each section because there are no extra sections to turn to. This prompted me to create a new class called Endpoint. Endpoint is a parent class which has two children inheriting from it: Turnout and Passthrough. A Passthrough is used when an Endpoint only connects two sections and a Turnout is used when an Endpoint is connecting more than two sections. To imagine the distinction compare the Endpoint at the corner of an ‘L’ shape to the Endpoint at the divergence of a ‘Y’ shape. The ‘Y’ gives options but the ‘L’ does not so the ‘Y’ Endpoint needs more and different functionality than the ‘L’ one. Passthroughs automatically change their own direction to match that of the train passing through them but Turnouts tell the train which way it will continue. Some other smaller features were also added like the locking of turnouts when not in a section connected to that turnout. This addition will be important when multiplayer is introduced because you don’t want a player on the other side of the track changing up the turnout you are about to use. This brings us up to date on the current status of the project. Below is a video of the current build running.
Blog: Weeks 4-6
by
Tags:
Leave a Reply