I've been working on a railroad system for a voxel game I'm making but pretty much starting over from scratch again after my previous system has caused so many head aches. In my previous setup, user places voxel rails and as the train engine moved from one to the next, every time train ran it would scan several blocks ahead and built a list of rails. Each rail stored a list of coordinates that were open for connecting to other rails. The train engine would check to make sure each rail was connected by checking these coordinates between two rails to see if they match (two rails facing each other properly side by side) and if they do, the rail is connected so the train could move forward. I ran into problems when the rails were at higher or lower elevations which added more complexity.
I was thinking of adding some sort of waypoint system instead but I'm having trouble wrapping my head around this insofar of making sure the next waypoint is correct facing track to the previous waypoint. Essentially each track in the railroad would be a waypoint but the voxel rails need to be correct facing ones, otherwise for example you may have problems like a front facing track and left/right turn track which might not connect but the waypoint system would still flow forward.
Has anyone ever done anything similar or can provide any tips or an overview on what the best approach might be? The railway system is 3d space, modifiable, and the tracks can be placed and destroyed any time.