Tuesday, October 23, 2012

Here is another update on the level editor I'm making. I had some struggles with the WinForms and XNA combination, because I couldn't use the Content Pipeline the way I was used to.

When you ran the program, it build all the assets with MSBuild in a temporary directory and removed those when you closed the program. This did allow me to use the assets, but the loading time became higher and higher if I added more assets. 

Changing the build directory

I figured, if I changed the build directory of the ContentBuilder-class (the one that handles the MSBuild-stuff), which I used from the WinForms example, it would build the files to a directory that wouldn't be deleted and was easy to find back. This gave me a folder of .XNB's which I could load directly using Content.Load<>(). Much faster!

But it was still rebuilding the files over and over. After some thorough investigation I noticed that the .XNB's get removed from the build-directory as part of the MSBuild-process. There wasn't a way to stop MSBuild from removing the files that already exist. So I still had long loading times. 

Moving the files

After some fiddling and thinking I came up with the idea to move the .XNB's to another folder just after the buildprocess. It worked! And it was one of the first times I've used recursion for something useful! (looping through the directories and finding the files that need to be moved.)

Keeping it up to date

The next problem was keeping the files up to date. If I change a file, I want it to be built to an .XNB for immediate use. I made a Console-app which updates every three seconds to see if files are changed. It uses an XML-file that saves the assets with information such as the path to the file, the type of the file (model, texture, shader), the last update time and the last build time. If the build time is earlier than the last update time, the file needs to be rebuilt and it will do just that.

The Clockwork Asset Builder is a Console-app that runs in the background with a little log that shows errors and which files get rebuilt. The "removing build-folder" is the removal of the temporary folder which gets cleared by MSBuild anyway. 

This program will be used in the background during the use of the level editor. I will build in functionality to make it automatically reimport adjusted assets, so you can see the changes immediatly!
You can check the code on GitHub if you're curious how it works. If you have any suggestions, let me know!


Post a Comment

Subscribe to RSS Feed Follow me on Twitter!