Add support for custom JSON constructors for vehicle sub-systems#490
Add support for custom JSON constructors for vehicle sub-systems#490edvinsternvik wants to merge 2 commits intoprojectchrono:mainfrom
Conversation
|
First of all, thanks for contributing this PR, @edvinsternvik. I've made a similar change to my local version of Chrono that allows me to do pretty much the same thing you are proposing. I have a few questions about your implementation:
Looking forward to your thoughts as well as feedback from others in the project. |
Hello, thanks for your feedback. Yes, the example should probably be something more like: Good suggestion, I can't think of a use case that wouldn't work with a map. I just decided to just follow the method that was already used in the code but using a map might be a cleaner approach. Yes a global registry would reduce the number of changes required in the code. I decided not to do it that way to avoid unnecessary global state as I generally think they make the code harder to reason about. But in this case the constructors are only going to be used in a handful of places so a global registry might be better than having to pass the constructors around everywhere. I welcome any opinions on point 2 and 3, so that I can modify the code based on what we decide. |
|
Edvin, thank you for the contribution. |
Currently vehicles can be constructed from JSON files, but only using the predefined templates. This pull request adds the possibility to supply custom constructors when creating a vehicle from a JSON file.
This can be used like this:
(main.cpp)
(ExampleDriveline.json)
{ "Name": "Example Driveline", "Type": "Driveline", "Template": "ExampleDriveline", "Stuff": { "Thing": 0.5 } }