Archive for August, 2009
Playing nicely with C#
by Andrew on Aug.10, 2009, under Uncategorized
Just as this past weekend was starting I came across a GDC presentation made by one of the guys from Ensemble Studios. Specifically it was about making their final game Halo Wars. It was a technical presentation with some very cool stuff, such as how they used multi channel heightmaps to give their landscape a 3D mesh rather than just a verticle offset for each vertex. However, the thing that caught my eye was the screen shots from their editor. It was all C# based. Ok I suppose it could just be generic managed Windows Forms, but I doubt it. Combining this with both the comments I’d overheard about how “nice” the interface was for one of the other dissertation projects and the fact I’ve been dying to have a go at C# tool dev and bridging native and managed libraries I went a head and did just that.
The first real step was putting into place the managed wrapper classes for my unmanaged library. After some looking around and not really finding anything that could help me much I decided to amalgamate all I’d seen and could assume into a best guess implementation. It turned out it was quite simple. Since I relied on a lot of interfaces already as well as my main library interface being bridged it worked quite well.
With the first manged library built and running I patched it into a simple C# frame that would list all the available nodes in a loaded module.
Next up was a little organisation. Modules are referenced within the library by a provided name. The loaded file itself is abstracted away. So if you load a module with the name ‘Core’ and it contains a module called ‘time’ you would create that node by using the name ‘Core::time’ where the ‘::’ is used to show a reference into a module is made. I figured the simpilest way to break that down visually was just a tree view.
With a proof of concept type implementation taken care of with regards to actually proving it works I started messing around with layout ideas. Naturally this ment snazzing it up a little with file menus, work spaces and of course an about box.
After playing around with default items in the work space I set about actually showing the procedures, both the current one being edited and a list of “grouped” procedures. The editor window is fairly straight forward in concept, it’s where the “nodes” will be for connecting up to make procedures. I had to use the property grid just because it seems everyone uses it these days. There are 2 types of visual nodes. The IO node and the Bound Node. IO Nodes are the first I started with. These just represent the inputs and outputs of procedure so. The bound nodes are those associated with a specific node in the procedure, these I didn’t get round to finishing as there’s some back end editing stuff I have to adjust to let them play a bit more nicely.
With the nodes floating about I spent time getting dragging to work a bit nicer as well as investigating how to make the nodes a bit more visually appealing. I hadn’t really thought about how they would look when I began so I just messed around and decided upon something fairly plain, simple but pleasant.
I finished off the weekends work for this by iterating again on the design of the node controls. These are now fully custom elements with no more hacked in place windows components that do nothing. The sockets are now more obvious as well as showing their connecting points. I also went back over the whole UI and rejigged it a bit to use it’s space better, offer more feedback to the user and try to provide more command buttons on the UI so the user can use them or the ones provided through the file menu.
I have to admit I enjoy working with C#. How quickly you can put together a UI is just one of it’s strengths. Setting up meaning full interactions between objects and over all structuring for happy interface development is quite straight forward. It’s not my beloved C or C++ but the tools Microsoft have provided for it inside of Visual Studio are excellent.
Alas as I created this editor I started tinkering with the notion of creating a second interface for my library. Essentially splitting the Application interactions into 2 logical parts. The original interface refered to just as “ProcLib” would be simple and straight forward, load procedures and run them, not much more. That would be for the runtime aspect. For editors the library provides a more flexible and open ended interface that can be used more for modifying and creating procedures. This proved to be some fun, but since it is back to C++ and technically after the weekend has finished I shall talk more about it in days to come.





