(Advice Welcome) Devlog - 03 - How to design extensible architechture for my particle simulator desktop application
I tried making a simple refactor - when I was first experimenting with the code, Whenever electrostatics were disabled the vector of charges for each particle was reset. This is obviously not great behavior for when you want to be able to quickly toggle modes on and off, so I tried making it so toggling electrostatics simply switches whether the simulation notices them or not, and not whether the data exists. This took 4 different attempts at compilation and playing around before I arrived at the expected behavior - and all I was doing was just deleting some code!
It became clear that even though my application is still tiny (under 1k lines of code) and even though I have only 2 modes (gravity and electrostatics), I already have spaghetti code.
Now I need to do one thing: design a safe and extensible architechture for adding new types of forces.
The first thing that needs to happen is deciding how each mode interacts with the particles. This is the easiest part: Each mode is told to calculate the force for which it is responsible for every particle, and those forces get added to an array of forces, and then the sum force for each particle is used to determine its new position. This alone means there will never be any meaningful spaghetti code.
Now comes the hard part: deciding how modes should be declared and added to the application. There are two approaches:
- Create an interface for modes which is known at compile time. This will lead to better performance due to optimizations, faster startup times, and more control for me over how the application works.
- Create an interface for modes which is registered dynamically at startup, this approach allows for 3rd-party extensions in the form of dll files that are dropped into some folder in the install directory. This leads to slower startup times, less optimizations due to the need of a stable ABI, and an overall increase in architechture size.
I don’t know what I should choose, but I would love to have someone’s input on which would be better for my project.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.