Tag Archive for 'as3'

ActionScript 3 Quine

A quine is a programm emitting its own source-code. I guess this is the most simple variant one could produce.

Continue reading ‘ActionScript 3 Quine’

Tweening and object pools

Some days ago I was writing a tween engine for our library here at Hobnox and when I was comparing it with the other ones out there which are quiet popular (Tweener, TweenLite) I was pretty surprised that my engine was performing about 10fps faster than TweenLite when tweening 1000 objects. It was 40fps for me, 28fps for TweenLite and 14fps for Tweener. It is not only faster but the memory usage is constant and small — on a Mac it was constant 11mb for my engine versus up to 22mb for TweenLite for instance.

Since I am currently not allowed to post the source-codes I want to talk a little bit about the ideas behind the engine.

Continue reading ‘Tweening and object pools’

Pratique d’ActionScript 3

We really have a premiere this time. Thibault Imbert just released his book “Pratique d’ActionScript 3″ for free.

The story behind this is pretty sad but I have to say this is an awesome move from Thibault. It is about 1000 pages and took more than a year of work.

So if you are French you definitly have to check it out. And do not forget to donate some bucks to support Thibault if the book is useful for you!

ActionScript 3 optimization techniques

If you attended my session about bytecode inlining at FITC Toronto you might remember that I said I have a document covering a lot of common optimization techniques.

After talking to so many of you and getting nice feedback I decided to release it in a state which is a work in progress.

My main idea is still to put this into a Wiki so everybody can share his or her knowledge. Since I am pretty busy the next weeks I do not know when this will happen so for now I hope you get some use out of the PDF.

Confusion (AS3 Remix)

This movie requires Flash Player 9

This little remix has been created using the Hobnox AudioTool. For the recording I used Audacity which is the reason why it does not sound very saturated — there is something wrong with my settings.

The mix itself is quiet simple but the 303 pattern is not 100% accurate I think. Anyways I love that sound. Remember the whole audio data is calculated realtime in AS3 (44.1khz, 16bit, stereo) …and I had to use my crappy laptop touch-pad while performing ;-)

The original song is “New Order - Confusion (Rave Mix)” which is also part of the soundtrack from the first Blade movie.

AS3 compiler open-source: the logical consequences

With the release of the Flex 3 SDK the ActionScript compiler (ASC) became open-source as well. As you know I am working on my own “compiler” to inline bytecode directly with ActionScript. My approach is a post-compile compiler because I wrote it while the ASC was still closed source and ther was no way to do that different.

I still like the approach but it is of course not the best way. The only logical consequence now is to write a patch for the ASC and add some new keywords to it. This would be also easier than what I have to do currently because I am working with bytecode only and the compiler is half a compiler and half a virtual machine. I think it would be great if a community starts to evolve around the SDK and builds a version with more advanced features. Nicolas?

Speedcoding #2

Another experiment from scratch in about 40 minutes. Speeded up by a factor of 15. This time well know perlin noise particles originally invented by André Michelle. At the end I set the frame rate of the SWF to one which does not look very smooth in the video. It seems a little bit to slow.

Update: Source is available here. This is the original version (with a license header) so be aware that it is not optimized or very readable.

Speedcoding

It is really fun to watch speedpainting videos. Why did nobody do the same thing using Flash? Here is my contribution. A particle explosion in one and a half minute. The video has been speeded up by a factor of ten. The result is not very interesting but maybe someone will pick it up and do something a little bit more beautiful to watch.

Update: Original source is available here. Remember that this was written in 15 minutes total so it is not very clean or optimized. For instance the Explosion object will stay in memory all the time.

Jens’ AS3 workflow special

If you understand German I would strongly recommend you to read the article series about AS3 development at the blog of Jens Franke. Jens is about to release around 10 to 15 posts in the next two weeks in his special.

And reading is not only worthwhile for your own knowledge. There will be a raffle at the end. Prices include a full copy of FDT3.0, four FDT3.0 discount keys and five books from O’Rielly. All in all a very nice idea from Jens.

Converting a Number to 4 bytes and vice versa

For the hell of it I wanted to implement the fast inverse square-root that has been flying around in the Quake3 source-code for instance. Fantastic game by the way. There has been quiet a lot of talk about this algorithm. So can we do that with Flash? No we can not. It would be nice but it is simply not possible because you can not just map a Number into an int. With languages like C++ you can. So first of all: I found already an approach that is very fast but not as nearly as good as the original algorithm. It is also not the same “magic”. It is just some newton iterations and faster but worse then 1/Math.sqrt(x).

So what do you need to implement the original inverse square root algorithm? A way to convert any number to its four byte representation aka the way it is stored in memory. The original algorithm is freakin fast because it does not have to calculate the four bytes. It can just juggle with them. Since we have to insert some heavy math here our approach will always be slower but it helped me understanding IEEE single precision numbers a lot. Maybe anyone has a use for this?

Remember the isqrt function is WAY slower than doing 1/Math.sqrt(x)!

[as]private function isqrt( x: Number ): Number
{
var xhalf: Number = x * 0.5;
var i: int = toFloat( x );
i = 0×5f3759df - ( i >> 1 ); // the magic first guess
x = toNumber( uint(i) );
x = x * ( 1.5 - xhalf * x * x );
return x;
}

private function toNumber( x: uint ): Number
{
//– precheck here
if ( 0xffc00000 == x )
{
return NaN;
}
else
if ( 0×7f800000 == x )
{
return Number.POSITIVE_INFINITY;
}
else
if ( 0xff800000 == x )
{
return Number.NEGATIVE_INFINITY;
}

//– can not shift because flash doesnt like it…
var v: Boolean = uint( x & uint(0×80000000) ) == uint(0×80000000);
var e: int = ( uint( x >> uint(23) ) & 0xff ) - 127;
var m: int = x & 0×7fffff;
var n: Number;

//– if e > 0 we can do 2^e very easy by shifting it
//– otherwise we do 1/(2^e) and 2^e can be achieved by shifting it
if ( e > 0 )
{
n = ( 1 + m / ( 1 << 23 ) ) * ( 1 << e );
}
else
{
n = ( 1 + m / ( 1 << 23 ) ) * ( 1 / ( 1 << -e ) );
}

if ( v )
{
return -n;
}

return n;
}

private function toFloat( x: Number ): uint
{
//-- do a quick precheck
if ( Number.POSITIVE_INFINITY == x )
{
return 0x7f800000;
}
else
if ( Number.NEGATIVE_INFINITY == x )
{
return 0xff800000;
}
else
if ( isNaN( x ) )
{
return 0xffc00000;
}

//-- calculate ieee single precision
var v: Boolean, e0: int, e1: int, m: int;
var f: Boolean = x > 0;

if ( x > 0 )
{
e0 = int( Math.log( x ) / Math.LN2 );
m = ( ( x / ( 1 << e0 ) ) - 1 ) * ( 1 << 23 );
}
else
{
v = true;
e0 = int( Math.log( -x ) / Math.LN2 );
m = ( ( -x / ( 1 << e0 ) ) - 1 ) * ( 1 << 23 );
}

e1 = e0 + 127;

//– usually here would go the test for e1 = 0×00 or e1 = 0xff
//– BUT we tested already and that’s why we do not do it here

//– be save
e1 &= 0xff;
m &= 0×7fffff;

//– merge into 4bytes
var float: uint;

if ( v )
{
float = 0×80000000;
}

float |= e1 << 23;
float |= m;

return float;
}[/as]




Close
E-mail It