Monday, April 20, 2009

MVC Patterns

I've gone back and finally implemented a model-view-controller system in my editor. I have had plans on doing this for over a year and some now but I finally got around to doing it. Basically, all of my data and algorithms on said data are stored inside of the 'model' while the 'view' of that data in terms of what the editor wants have been broken apart. The collision data for instance is something that belongs in the view since it's an interpretation of the model and only the editor cares about that. The mesh name that an entity is using belongs in the model since it is an integral part of the data. The graphical data associated with that is handled by the view since different 3D engines might represent that 3D model differently.

What this allows me to do is to work with my entire scene without having to load a 3D engine. This will work out great for tools since they can have the typed data that they want without having all of the graphical parts associated with it. We can attach different views as well for different applications.

The other important thing this allows me to do is unit test my business logic separate from my UI interactions. For example, I can now test that my terrain modeling tools provide the proper deformations or material modifications since the graphics engine doesn't need to be loaded. As I've already built up a small testing suite in NUnit, this works out really well. I can make sure that the only parts to break in the future are the UI components. If a bug is reported that is related to the business algorithms, I can fix it, write a unit test for it, and it'll never make it into the build again.

This has broken a few things that require refactoring but it'll be worth it in the end. Unit testing has proven invaluable for finding bugs in other parts that I believed my current changes couldn't possibly affect.

I'm also working on the actual resource management system again for my editor which should be pretty kick ass. I had a primitive version of what I wanted done a long time ago but I want to spend some more time on it again. It should allow for a pretty nice work flow.

Thanks to someone at work for reminding me that there is at least 1 person out there reading this. It's also nice to just have some place to ramble my thoughts off.

No comments: