Tuesday, January 24, 2017

C++ integration with .NET Framework

I was making a bit more progress on the Plate Tectonics simulator when a thought occurred to me. The simulator is written in C++ and I'm compiling it as an executable with a relatively-recent edition of Microsoft Visual Studio.  The simulator, and some of the other libraries it relies upon, are LGPL licensed.  I can wrap the C++ code for compatibility with the .NET Framework, and produce a DLL, licensed under LGPL. Then I can use it from other software with more or less restrictive licenses (MIT, BSD, or something proprietary) without problems, because it is a library.

It seems like it should be fairly simple, technically speaking, but I've never done it before. I found a nice tutorial. The only sticking point is I haven't figured out how structs can be translated/marshaled between managed and unmanaged (native C++) code. For passing the ever-growing list of parameters for the simulation, I'll have to either do so or else make them available as properties of the main simulation class (not my preferred approach). I'll worry about it once I've got the Plate Tectonics simulator otherwise finished.

You may wonder why I'd want to do this.  The main reason is because while the simulator is a good starting point for planet generation, it is a poor stopping point.  Additional terrain generation, or even just pretty maps, should follow from it.  This is one approach to that goal.

No comments:

Post a Comment