Hong, Guil Dong · 2024-02-07 15:19
i'm wondering, what design patterns are used for real time interactive graph-based simulations? for example, how do you keep the layout of the interactive circuit diagram sperate from the strucutre and simulation state of the circuit in an electronic simulation program?(USER WAS WARNED FOR THIS POST, You should always elaborate on your opinions rather than just spilling the soykaf.)
Naomi Nascimento · 2024-02-07 17:51
Just solve the problem. The structure will be more obvious when you have something to structure.
Hint, adjacent memory > pointer web.
Erik Johansson · 2024-02-07 20:18
>>38301
I am trying. I think the graph structure and the static properties of the elements should be handled seperately from the layout constraints on one hand, and from the simulation state on the other, but without some overcomplex ID system, I can't see how to avoid storing information relevant to the layout and ui in the same structure as the more fundamental information. It might be easier to keep the simulation state seperate, but not if you want to allow for simulation continuity while making small changes to the model.
Drifter · 2024-02-09 17:22
i believe the answer will depend on how sophisticated your system should be. Effects like induction between wires require the simulation to incorporate information that would usually be limited to rendering in a model agnostic to it. If you keep it simple you can also simplify your data model a lot:
For a simpler model i would just create a vector array holding the graph nodes (circuit elements) which are themself just a class with 2 variables defining type & pointer array of connections to other graph nodes. The renderer would have its own list of elements with a pointer to the respective graph node to retrieve variables like how much ohm a resistor should have + position on the circuit board. Connections would be another separate list because the display of connections is just for your own visualization if you don't simulate the previously mentioned side effects. You can basically render the circuit elements and draw the connections separate after drawing the elements.
For the simulation you can just go through the list of elements fish out power and walk through the graph from there.
bit · 2024-02-09 18:02
>>38300
Not separating the components may be better.
Have an unchanging copy of the layout, and use that to create the simulation structure & initial state.
Leto Atreides I · 2024-02-10 12:31
>>38312
at that point, don't you risk making the execution of the simulation depend on the implementation details of the gui?