mocha-engine / mocha

Mocha: A work-in-progress 3D game engine
GNU Lesser General Public License v3.0
53 stars 7 forks source link

Compiler improvements #42

Closed peter-r-g closed 1 year ago

peter-r-g commented 1 year ago

This PR overhauls the hot load project with a lot of items:

NuGet package support

All of this is handled by the hot load compiler now so you can hot load NuGet packages and use them in games. The compiler also handles dependencies inside the NuGet packages recursively.

Project references

The csproj is now checked for any project references. With this, we no longer need to hard code references to some of the Mocha DLLs. The compiler does all of it for us.

DLL references

The compiler also checks for any DLL references and includes them in the compilation process.

IMemberUpgrader priority

The IMemberUpgrader interface now has a priority property. This will define how important it is to be checked first. This is used to replace the hard-coded list of upgraders. So now we can use reflection to get all upgraders and not worry about ordering it correctly.

Internal csproj generator

While the T4 text generator was a nice start. It is ancient and barely supported tooling in VS made it annoying to work with. A major issue we have with it right now is that it will not generate on the project build. So new people picking up the project have to find the T4 file and generate it themself. That has been ripped out now and is replaced with a basic csproj generator using System.Xml classes.

More reloading opportunities

Whenever the project's csproj or its JSON has been edited it also triggers a hot load. This way you can edit references at runtime and still have it all hot load fine.

Conclusion

With all these changes from what I can tell the performance is roughly the same under the same situations. Of course, when it comes to NuGet packages it will become incredibly slow since it has to fetch the packages online. But overall it seems pretty smooth to me. This PR also makes everything internal and sealed because to my knowledge none of the functionality in the hot load project will ever be used outside.

https://user-images.githubusercontent.com/11802285/215387883-e1f1e4fc-3e88-4469-9d26-2d1df7c18ec8.mp4

xezno commented 1 year ago

Looks good to me, will merge shortly. The new project generator is especially welcome since I'm not too keen on text templates either, doing XML is a much better solution especially long-term since it means we can expose even more options to developers in future. As always, great code and thanks for this! Your contributions are always welcome.