soundprojects / trainsim

Train simulator written in Rust
1 stars 0 forks source link

Drawing complex tracks automatically #10

Open soundprojects opened 2 years ago

soundprojects commented 2 years ago

I want to research a way of defining graph like tracks and switches and how they relate. Then the result of this needs to be passed to a layout function which looks at the amount of different heights and widths that we need and creates the most optimum layout for this track.

It might be that we need to manually pass some offsets as well (maybe we don't want a certain track or switch to be drawn with a huge size for readibility). I want to seperate the worker logic from the UI logic. Slint has some cool features and it is also possible to compile slint code from the backend but that would require all UI to be compiled and run which I don't like. I do like the for loop drawing which Slint can do though, so if I can create a structure which contains proper offsets for all the elements, the drawing should be fine.

  1. Create elements from our graph structure using our tracks/switches
  2. Look at total amount of switches / splits to determine height levels for drawing
  3. Space out elements and calculate x and y offsets
  4. Return result to Slint for drawing paths
soundprojects commented 2 years ago

We left Slint for Egui for now. This allows us to simply pass our entire TrainSystem struct which will have some handy methods for possible routes and connections.