Some days ago I found an article about fire as a fluid on the very excellent page of Hugo Elias. Most of you will know him because of his famouse perlin noise article. I liked the idea behind the way how to simulate fire as the reaction of fuel and oxygen. So I started to reproduce that fire and got stuck at the fluid part.
I did not know anything about the mathematical natrue of fluids. So I followed the link to the publications of Jon Stam. Fluids are a very difficult natural phenomena in my eyes. If you do not really want to read about fluids you might have a look at the implementation of a stam-solver in C. As you can see this is something Flash can not handle. But then I also saw a stam-solver done in Java.
This is why I thought it could be possible in Actionscript too. But it is not. First of all I tried to do the stam-solver in a nice way with packages etc. It was much slower than the Java version. I thought it might be because this was the first time I worked with packages (like flash.util.trace I did something like de.je2050.fluids.solve). The direct clone of the Java source in Flash was also much slower than the Java version. What a shame. It is not just slower, it is even not 1fps.
So what I did was reducing the stam solver to lower quality. The result is a bad looking fluid (which is also colored like fire). Too bad that Flash has fallen behind the current standarts. The smoke looks so nice but it took me about 10 minutes to render that in Flash ;)
Update: A video of this beautiful smoke is also available. I have done this using C++ instead of Flash.
Some days ago I found an article about fire as a fluid on the very excellent page of Hugo Elias. Most of you will know him because of his famouse perlin noise article. I liked the idea behind the way how to simulate fire as the reaction of fuel and oxygen. So I started to reproduce that fire and got stuck at the fluid part.
I did not know anything about the mathematical natrue of fluids. So I followed the link to the publications of Jon Stam. Fluids are a very difficult natural phenomena in my eyes. If you do not really want to read about fluids you might have a look at the implementation of a stam-solver in C. As you can see this is something Flash can not handle. But then I also saw a stam-solver done in Java.
This is why I thought it could be possible in Actionscript too. But it is not. First of all I tried to do the stam-solver in a nice way with packages etc. It was much slower than the Java version. I thought it might be because this was the first time I worked with packages (like flash.util.trace I d
Adobe announced the release of several APIs on their Labs site. Theese libraries (should) speed up your developement flow. But lets go one step deeper and take a detailed look at the corelib. The corelib offers a lot of useful utils like the String and Array util.
All that stuff is very great and saves a lot of time. But there are still some inefficient parts in the corelib that scream for optimization. For example the ArrayUtil. Take the function ArrayUtil.copyArray. This function returns a copy of the given array. Now look at the implementation.
[as]
public static function copyArray(arr:Array):Array
{
var len:Number = arr.length;
var out:Array = new Array();
for(var i:Number = 0; i < len; i++)
{
out.push(arr[i]);
}
return out;
}
[/as]
Look at the beautiful for loop and then imagine an array with thousands of elements. Could take 2 or 3 seconds sometimes. I think somebody should tell Adobe about the trick using Array.slice();
[as]
var arrayCopy: Array = arrayOriginal.slice();
[/as]
This is much faster since slice() is a native function. There is also the StringUtil.replace() function which does not make use of the new regular expressions. Maybe there are more functions that could be slightly optimized. This is what I would expect from a good API. It should be well documented (which it is) and doing its job in the best way. I do not want to take a look at the other APIs since this was just a short example. But the conclusion is that you should check what you are using and how it is done.
Adobe announced the release of several APIs on their Labs site. Theese libraries (should) speed up your developement flow. But lets go one step deeper and take a detailed look at the corelib. The corelib offers a lot of useful utils like the String and Array util.
All that stuff is very great and saves a lot of time. But there are still some inefficient parts in the corelib that scream for optimization. For example the ArrayUtil. Take the function ArrayUtil.copyArray. This function returns a copy of the given array. Now look at the implementation.
[as]
public static function copyArray(arr:Array):Array
{
var len:Number = arr.length;
var out:Array = new Array();
for(var i:Number = 0; i < len; i++)
{
out.push(arr[i]);
}
return out;
}
[/as]
Look at the beautiful for loop and then imagine an array with thousands of elements. Could take 2 or 3 seconds sometimes. I think somebody should tell Adobe about the trick using Array.slice();
[as]
var arrayCopy: Array = arrayOriginal.slice();
[/as]