« Posts under Tools

Making Your Files Merge Friendly

Merging is a fact of life for most of us.  Eventually two users touch the same files and a conflict must be resolved.  For programmers merging is a daily activity, but what about the content creators?

If two artists touch the same level, have your tools programmers made enough of an effort to make merging possible and if possible as painless as can be?

Here’s a handy checklist,

1 – Use XML/JSON (or some other text based file format)

It’s slower, it’s bigger but it’s going to make merging possible.  If your level files are binary blobs merging without a custom tool just isn’t going to be possible.  Using XML or JSON are the simplest text based alternatives because there are already many libraries for reading and writing them.

2 – For XML – Give Each Attribute a Line

If you’re using XML, you should make sure to write out the files such that every element and every attribute receives its own line.  If you don’t do this it will make conflicts a lot more likely if two users touch the same object.

If you’re using JSON, having each attribute on its own line is the norm unless the library is attempting to keep the text compact.

Here’s a quick example, note that after separating the attributes the merge tool handles the conflict correctly while it fails to do so when they are on the same line.

nonewline
Figure 1 – Attributes all on the same line

newline
Figure 2 – Attributes on different lines

If you’re using .Net this can be achieved very easily by changing the default XmlWriterSettings with the NewLineOnAttribute property set to true.

C#
var settings = new XmlWriterSettings()
{
    NewLineOnAttributes = true
};
 
using (XmlWriter writer = XmlWriter.Create(filestream, settings))
{
    // Write out document...
}

3 – Maintain Order

Always write out the order of the data the same.  This one is pretty easy, the only real pitfall is to make sure your data structure and undo/redo system are working correctly.  For example, if you happen to store your objects in a list and someone removes and object at the front, but when it’s undone it’s inserted at the end of the list (Even if the UI doesn’t reflect this) this could affect your output order.

4 – Don’t Add New Objects At The End

When you go to save the entities don’t write them out in the order they were created.  This will definitely result in a merge conflict.  Because it ensures that if two users edit the file and both add an entity they’ll both show up in the same location and confuse the merge tool.

One thing you could do is to sort them based on a GUID that is stored as part of the objects data.  Sorting based on GUID ensures a lower probability of collisions occurring when two users both add objects.

Alternatively a sorting based on a string containing the machine name of the original creator of the object is another idea.  It would ensure every user touching the file would be inserting to their own section of the file instead of everyone inserting to the tail.

Project Photofly Experiment

Last week we were sitting around the office wondering if it would be possible to place ourselves in a game world with Autodesk’s Project Photofly.  How cool would that be?  We thought we might be able to scan one of us in a T-pose and then use Mixamo’s Auto-Rigging tool to create a rigged avatar.  Then we could be running around a level in front of our Kinect as ourselves.

Sadly it never went past stage one.  It’s harder than you might think to hold a T-pose for 3 minutes while someone circles you twice snapping pictures at 10 degree intervals.

I don’t have any pictures of the results; I came out looking like the elephant man.  We’ll probably try again at some point, but in the meantime I made another scan of a pair of static objects that was turning out pretty good until I got to the back of the monkey.

YouTube Preview Image

All in all Autodesk’s Photofly software is pretty cool.  It’s still lacking in the area of iteration and debugging.  You can try manually tagging photo matchup points between images to give it a better idea on how the images fit together but it takes awhile for the data to be processed in the cloud.  It’s also unclear where some data comes from, or why portions of the background become part of the foreground mesh.  If it had better feedback for how that data became part of the mesh cleaning up the results would be a lot easier.

Also, if you own a camera with a sports video mode that captures at 60 FPS you can just slowly circle the subject and then dump all the frames using ImageGrab.  Which is way easier than snapping individual pictures.

I wonder if I could generate 3d art for a game jam…

Terraria: The Auto-Saving Server

After beating Minecraft (not really) I thought my addition to these blasted sandbox mining games was satisfied.  Sadly, I was wrong.  I started playing Terraria a few days ago and its got many more game elements than Minecraft.  It’s also wildly addicting if you’ve got a sever case of ‘Got’a’ Catch’em Alls’.  It’s also possibly the real world equivalent of Heroin Hero.

In any event, I setup a server for my friends and I to play only to discover that the server does not auto-save the world.  So if it crashes or is shutdown improperly, everything in the world resets.

So I wrote a little bit of code to fix it and decided to share.  It’s a simple bootstrapping program, you give it the file path of the Terraria server executable as the first argument and then all the other arguments to pass to it as a single string.  It then sends save commands to the server every 10 minutes.

If you want to just download a compiled version for yourself, you can download it here.

If you were to place it in the same directory as the TerrariaServer, you’d run it like this:

Text
TerrariaAutosave.exe TerrariaServer.exe "-config serverconfig.txt"

P.S. You never catch the dragon.

GeSHi / HLSL

One of the plugins I use for my blog is wp-syntax, which is a pretty fantastic plugin for embedding code in posts.  It uses GeSHi as its syntax highlighter to process the code, but it lacked a scheme for HLSL.  So I hacked out my own and had intended to create a post about it to share with others.  I finally remembered to do that, so feel free to snag it from here.  To use it in a wordpress blog, you just need to extract the php file and place it here “wp-content\plugins\wp-syntax\geshi\geshi” with the other GeSHi syntax php files.

Nsightful

It took several versions before enough kinks got worked out in Nvidia’s Parallel Nsight Graphics/CUDA debugging application before I could successfully profile my Hierarchical Z-Buffer DirectX 11 implementation.

However, it looks like the latest version which is now completely free with pro level functionality debugs my Hi-Z implementation like a champ!

The tool is really slick.  It’s much closer to the experience I’ve wanted to have when debugging the GPU on windows.  Thus far it feels much better than the windows version of PIX, with more functionality and information.

nsight_hiz11

I was finally able to get some numbers I trust are more accurate for my Hi-Z DX11 implementation on a GeForce GTX 480.

?µs Some number of occluders being rendered
85µs Downsample the Hi-Z mipchain
27µs Testing 900 bounds in the compute shader

So if you extrapolate that data, that’s culling 10,000 bounds for ~0.3 milliseconds of GPU time.  Plus however long it takes you to render your occluders, which should hopefully be cheap and crammed into a deferred command list.

I’m sure you could improve upon the performance of my compute shader that does the work of figuring out what should be culled by just better managing the thread groups.  I just thought it was great I finally was able to profile my code with Nsight because I’ve tried every time a new version came out and was thrilled to see it working.