On a previous project I was tasked with creating dynamic lightning that could strike the player if too close to a storm cloud. This was an interesting challenge for me as the lightning had to look great and be dynamically rendered on everything from a high end iOS device to a low end Android device. As this was in the Unity Game Engine the language of choice was C#, which is good as C# is my language of choice these days.
While researching procedural generation for this effect I ran across a lot of implementations that stuck to using multiple line segment structs shoved into a list. This really would not do. A single lightening effect could sprawl out to hundreds or thousands of line segments. Then it would need to be converted into a bill-boarded mesh. The game could have up to 4 Lightning clouds on screen at a time with up to 4 more Queued up above. So at most it would have to support 6 dynamically generated lightening strikes at a time. The lightening had between one and three main bolts, with a probability that at any point along the line another branch could form. It was a big branching fun looking lightening and enough Vector math to crush the heart of the poor mobile cpu.
My color space conversion class has been pushed to Bitbucket and Github. As this is managed code the conversions are not suitable for real time use, but more that suitable for general use. I did not use .Net Color structure in the conversions, I instead opted to use Numerics.Vector4. This allows the color conversions to take advantage of simd hardware where available.This will provide a speed up if your build is x64, with the optimize flag enabled. Here is a list of first release conversions available in the class.
All Conversion are in floating point and support an alpha channel. Each Method is overloaded for single color vector or for a color vector array. It is MIT licensed making it free to use for any purpose. If you wish to contribute just branch and let me know.
Recently I have been working on a .u3d (ECMA 363 4th Edition) compliant decoder in c#. In the specification for the External File Reference block is the requirement to support file name filters that may have the wildcard characters ‘?’ and ‘*’. Dot Net does not include a native method for matching wildcards characters in strings, so I went online to see what solutions others have come up with.
Turns out a really popular response to matching wildcards is to use RegEx. Unless the application is just doing this check once and never again, I cannot communicate just how poor this solution is. It is by far the simplest; a couple lines of code and you are done. RegEx is very powerful but that power comes at a cost; I had to remove it from the full test as it was just too time consuming. Recursive algorithms also seem to be a popular choice, but again they can be slow. I tried the Visual Basic “trick” and even though the performance was more suitable it failed on many of the test cases. The test consists of 100 different strings and wildcard strings that I gathered from the web. Some are “gotchas” intended to test if the method meets the requirements of wildcard rules others are possible uses like URLs. I did eventually find a method that only fails on one test case. I still felt this method was too slow for use in a file loader/decoder. So I decided to throw my hat into the ring and see if there was any way, ugly or elegant that would be faster and still pass every test. I am accustomed to writing real time code that must perform its duty fast enough that the application can go through a full update in 16-33 milliseconds (60 – 30 frames per second). I was determined even if it had to be some sort of dirty hack.