Nicolas Cannasse Blog http://ncannasse.fr/ Blog haXe Wiki System en haXe 2.06 Available ! http://ncannasse.fr/blog/haxe_2.06_available http://ncannasse.fr/blog/haxe_2.06_available Sat, 14 Aug 2010 18:02:05 +0200 Sat, 14 Aug 2010 18:02:05 +0200 Nicolas Cannasse Nicolas Cannasse <p>I'm please to announce on behalf of the whole haXe compiler team that the 2.06 release of haXe is no...</p> <p>I'm please to announce on behalf of the whole haXe compiler team that the 2.06 release of haXe is now available on <a href="http://haxe.org/download" class="extern">http://haxe.org/download</a> !</p> <p>The main changes in 2.06 are :</p> <ul><li>metadata support, see <a href="http://haxe.org/manual/metadata" class="extern">http://haxe.org/manual/metadata</a></li><li>allow custom haXe serialization, see <a href="http://haxe.org/manual/serialization" class="extern">http://haxe.org/manual/serialization</a></li><li>allow to directly access the classes in SWF libraries in Flash9, and also allow several <code>-swf-lib</code> parameters</li><li>flash9+ now use native Xml parser : a lot faster, but more strict with namespaces</li><li>improvements in code generation for PHP and C++ platforms</li><li><code>https</code> support in haXe/PHP</li><li>a lot of bugfixes and improvements on all platforms</li></ul> <p>See the whole list of changes here : <a href="http://haxe.org/file/CHANGES.txt" class="extern">http://haxe.org/file/CHANGES.txt</a></p> <p>Enjoy !</p> Speaking at FITC/SF http://ncannasse.fr/blog/speaking_at_fitc_sf http://ncannasse.fr/blog/speaking_at_fitc_sf Mon, 9 Aug 2010 13:36:34 +0200 Mon, 9 Aug 2010 13:36:34 +0200 Nicolas Cannasse Nicolas Cannasse <p>I went already to SanFrancisco <a href="/blog/flash_gaming_summit" class="intern">earlier this year</a> and since I'm quite busy with my daily work at <a href="http://motion-twin.com/english" class="extern">Moti...</a></p> <p>I went already to SanFrancisco <a href="/blog/flash_gaming_summit" class="intern">earlier this year</a> and since I'm quite busy with my daily work at <a href="http://motion-twin.com/english" class="extern">Motion-Twin</a> I wasn't really sure about going to another conference this year.</p> <p>However, nice people from <a href="http://www.influxis.com" class="extern">Influxis</a> have been invited me for FITC San Francisco as part of their <a href="http://www.fitc.ca/voodoo/" class="extern">Voodoo Lounge</a> in-conference so I'm very happy to talk here about <em>Everything you wanted to know about haXe, but were afraid to ask</em>, make sure to attend if you're coming to FITC, and if you're not, they will be a <b>live streaming</b> of the talks.</p> <p>No reason for you not to watch then ;)</p> haXe support in FDT ! http://ncannasse.fr/blog/haxe_support_in_fdt http://ncannasse.fr/blog/haxe_support_in_fdt Thu, 22 Jul 2010 21:21:52 +0200 Thu, 22 Jul 2010 21:21:52 +0200 Nicolas Cannasse Nicolas Cannasse <p>I often - at least once a year - go to Flash conferences to talk about <a href="http://haxe.org" class="extern">haXe</a></p> <p>A lot of ActionScript de...</p> <p>I often - at least once a year - go to Flash conferences to talk about <a href="http://haxe.org" class="extern">haXe</a></p> <p>A lot of ActionScript developers are interested in giving haXe a try, but the main reason for not giving it a try is because of (lack of) IDE support.</p> <p>Back in the old days, it was hard to switch between languages because of the need to adapt to a new syntax and to the changes in standard library. Since you needed to remember all the API, you were spending most of your time switching between your code editor and the API documention.</p> <p>Today, IDE completion is very useful and will help you to learn/discover the API of a new language. With a good syntax support, you'll also avoid most of the troubles getting used to a new syntax. But while on one hand a good IDE will help you discover new languages, on the other hand switching to another IDE or (even worse) back to a bare text editor is very hard for some developers.</p> <p>This is one of the many reasons why IDE support is important for haXe. </p> <p>In order to ease IDE integration, we have been supporting from a long time <a href="/blog/haxe_completion" class="intern">compiler based completion</a>, so you won't have to rewrite haXe Type Inference algorithms in order to display completion tip. This support help the community developing haXe support in several IDE, including <a href="http://macromates.com" class="extern">TextMate</a>, <a href="http://flashdevelop.org" class="extern">FlashDevelop</a>, Emacs, Vim, and a <a href="http://haxe.org/com/ide" class="extern">lot of others</a>...</p> <p>But every developers have their own preferred IDE and I being myself IDE agnostic, I'm always happy when I see a new IDE supporting haXe.</p> <p>This is why I'm very happy today to announce the alpha version of <a href="http://fdt.powerflasher.com/blog/?p=2233" class="extern">haXe support for FDT</a>, one of the best Flash IDE out there, widely used by ActionScript developers around the world !</p> <p>Many thanks to PowerFlasher and Influxis, and the FDT team to making that happen !</p> Apple Gate http://ncannasse.fr/blog/apple_gate http://ncannasse.fr/blog/apple_gate Mon, 12 Apr 2010 22:14:46 +0200 Mon, 12 Apr 2010 22:14:46 +0200 Nicolas Cannasse Nicolas Cannasse <p>For those that haven't been following recent news, Apple changed their iPhone Apps Developers requir...</p> <p>For those that haven't been following recent news, Apple changed their iPhone Apps Developers requirements by only allowing Objective-C (and a few other) languages to be used to write such apps. </p> <p>What seems to be a move to prevent Adobe from integrating iPhone target in their upcoming CS5 release since it directly compiles AS3 to ARM through LLVM is actually annoying much more people than Flash fanatics, since many developers are using other languages for iPhone dev.</p> <p>According to some people on the haXe mailing list, it seems that <a href="/blog/haxe_for_iphone" class="intern">haXe for iPhone</a> is safe since Apple would only want to ban people avoiding going through XCode compiler, which would also make platforms such as Unity safe.</p> <p>I'm personally not surprised by Apple stance, since I've always seen their products as a beautiful and nicely designed <a href="http://en.wikipedia.org/wiki/Vendor_lock-in" class="extern">lock-in</a>, with very low level of interoperability and openness, everytime justified for the supposed sake of the &quot;end user experience&quot;.</p> <p>What makes me more surprised is that a lot of developers are still trying year after year to convince others (or themselves ?) that Apple is cool and love developers and open source, while the company actions have mostly headed the other way...</p> <p>Anyway, I really enjoyed reading <a href="http://gamehaxe.com/2010/04/10/bravo-apple/" class="extern">Hugh blog post</a> on the subject, check it out it's worth reading (and the comments of people not understanding irony are funny as well).</p> FlashGamingSummit Slides http://ncannasse.fr/blog/flashgamingsummit_slides http://ncannasse.fr/blog/flashgamingsummit_slides Fri, 12 Mar 2010 21:22:35 +0100 Fri, 12 Mar 2010 21:22:35 +0100 Nicolas Cannasse Nicolas Cannasse <p>I was presenting haXe at the <a href="http://flashgamingsummit.com" class="extern">FlashGamingSummit</a> on Monday, that was a nice one-day conference and my ...</p> <p>I was presenting haXe at the <a href="http://flashgamingsummit.com" class="extern">FlashGamingSummit</a> on Monday, that was a nice one-day conference and my first time in SanFrancisco. I'm currently attending the GDC which is also quite interesting.</p> <p>I tried to focus my talk on haXe from the point of view of flash game developers. Being one myself, I think there's many reasons why haXe is perfectly suited for such a task, performances being one of them. </p> <p>The Kube demo I was showing is an actual game that's been released on <a href="http://kube.muxxu.com" class="extern">http://kube.muxxu.com</a> (sorry, french only so far) and that is using a realtime raytracing engine running in Flash with low-res old school looking textures.</p> <p>Here's a screenshot of the actual game :</p> <p><img src="/file/kube.jpg" alt="kube.jpg" class="intern"/></p> <p>You can download my slides in you want to have a glance at what I was presenting :</p> <p><a href="/file/FGS2010_haxe4GD.pdf" class="file file_pdf">FGS2010_haxe4GD.pdf</a></p> Back in 2005 http://ncannasse.fr/blog/back_in_2005 http://ncannasse.fr/blog/back_in_2005 Sun, 14 Feb 2010 21:46:15 +0100 Sun, 14 Feb 2010 21:46:15 +0100 Nicolas Cannasse Nicolas Cannasse <p>I was just looking at my emails archives. Actually we installed our IMAP server at Motion-Twin by th...</p> <p>I was just looking at my emails archives. Actually we installed our IMAP server at Motion-Twin by the end of 2005 so I almost have all my sent/recv mails from this time. More than four years of words, and so much energy (and time) spent while writing them...</p> <p>November 2005 was also the time that we started a private mailing list with the main people of OSFlash. It was including OSFlash cofounders - Aral and myself - as well as people working on the big projects at this time : John Grden, Chris Allen, Dominick Accattato and Luck Hubbard from Red5, and Edwin van Rijkom from Screenweaver.</p> <p>We started discussing about a possible <em>OSFlash Manifesto</em> which would act as a foundation for the newborn and growing OSFlash community.</p> <p>Here was my original take on the Manifesto :</p> <pre>Date: Sun, 27 Nov 2005 12:05:02 +0100 From: Nicolas Cannasse &lt;ncannasse@m.....com&gt; Subject: [Roundtable] Manifesto RFC The OSFlash Manifesto --------------------- Fifteen years ago, there was no Web. Nothing. The WWW protocol was invented back in 1990 by CERN scientists in order to share research informations. Since then, the web and the whole internet have been growing at a tremendous pace, bringing a place to communicate and share for users around the world, a place where everybody can talk freely, a huge quantity of online services and wealth to a lot of people and companies. What made possible this growth is the openness of Web protocols and file formats. Anybody can &quot;speak the web&quot; freely, by sending HTML documents using HTTP protocol over a TCP/IP connection. The Web is not owned by a particular company, it's a whole ecosystem of mixed open and prioprietary tools, all using theses open protocols and file formats. Flash is a technology that is widely present on the Web. Yet, the number of Flash developers is still way beyond the number of web developers. There is a reason for that : Flash is a proprietary platform owned by a private company named Macromedia (now Adobe). The OSFlash community is composed of Flash enthousiasts and technology savvy people that see an interest in developing Flash further its current status. As a community, we have two goals : One is technical. As most of us are using Flash on a daily basis, we are cooperating together in order to create a better set of tools. The tools sold by Macromedia cannot always be the perfect fit for any kind of usage. As a community, we're helping each other and are trying to find the best way to complete a given task. The other is ethical. We don't want to be &quot;lock-in&quot; into a particular proprietary solution. We don't want one part of the Web platform to be owned and fully controled by a private company. As a community, we are then working at learning the different protocols and file formats needed in order to &quot;talk Flash&quot;. We are doing that in a legal way, through observation of the existing. And we are then providing the documentation and tools released under an Open Source license so that everybody can openly build Flash content. Additionally, we are requesting that Macromedia open further the Flash platform, by doing the following : a) fully document without any licensing restriction the different protocols and file formats used by Flash. The OSFlash community is doing that, and this will surely bring a whole set of Open Source tools. By having an official documentation, Macromedia can create a whole ecosystem of other companies that will create other Flash-related tools. We think that this will benefit the Flash platform. b) allow the Flash Player to be embedded and reused without any restriction, so that the Flash technology will not only be usable on the Web but inside applications, bringing a lot of new people into making Flash content. With current Player restriction, the platform is not even available of redistribution. c) facilitate the emergence of third party compatible Flash Players, just like Sun did for Java. This will put again the Flash technology far beyond its current limits and bring in return more users into Flash. d) ultimaly, create a consortium representing both companies and users, that will openly discuss the evolution of the Flash technology in a democratic way. If Macromedia opens the Flash technology, we can see a future in it. If they don't, that will ultimaly be the death of the idea of &quot;Flash as a platform&quot;. Creating a web proprietary platform, should not and actually cannot be done. Any company following this path will fail in doing so. Following the experience of Democraty and the Web : openness bring growth to everybody. -- EnD -- Nicolas</pre> <p>That was of course a bit bold at this time, but four years later remains quite actual since the situation hasn't changed much since then.</p> <p>This manifesto was not approved by Aral which had his hands on OSFlash.org so after a few weeks of discussions we didn't reach anything and we were not able to establish OSFlash as a community and to act as one. From there, OSFlash community began splitting among specific projects, from which came very nice pearls such as PaperVision3D, Red5, and my own haXe.</p> <p>Today OSFlash is no longer an active united community. There are a few posts on the mailing list but nothing really happening. Maybe things would have gone a different way if we were able to agree on this Manifesto, back in 2005...</p> Flash Gaming Summit http://ncannasse.fr/blog/flash_gaming_summit http://ncannasse.fr/blog/flash_gaming_summit Wed, 3 Feb 2010 21:30:20 +0100 Wed, 3 Feb 2010 21:30:20 +0100 Nicolas Cannasse Nicolas Cannasse <p>I'm trying every year to speak at least at one international conference. Attending to a conference i...</p> <p>I'm trying every year to speak at least at one international conference. Attending to a conference is a good way to keep me updated with what's happening in the <em>real outside world</em>, and I also like to talk about my work while I'm there ;)</p> <p>I don't have much free time, I dislike airports, and I'm married : three good reasons why I'm also limiting a bit my involvement within the &quot;conference loop&quot; compared to some of my good Flash friends which are doing something like five (or more) conferences a year. </p> <p>Since I like to meet new people and learn new things, I think it's best to go as much as possible to different conferences. This year I will be very happy to speak about <a href="http://haxe.org" class="extern">haXe</a> at the <a href="http://www.flashgamingsummit.com" class="extern">Flash Gaming Summit</a> conference which takes place in San Francisco next month !</p> <p>This is a bit a side-event of the bigger Game Developer Conference 2010 so I'm sure I'll have a lot of fun there, and meet people that want to hear more about how to develop Flash games with haXe.</p> <p><b>EDIT</b> : I decided to the stay the whole week in SF and attend the GDC at the same time, so if I know you and if you are around, drop me an email so we can meet.</p> <p>See you (maybe) there !</p> haXe Community Meeting http://ncannasse.fr/blog/haxe_community_meeting http://ncannasse.fr/blog/haxe_community_meeting Tue, 26 Jan 2010 16:51:34 +0100 Tue, 26 Jan 2010 16:51:34 +0100 Nicolas Cannasse Nicolas Cannasse <p>The haXe community is having an IRC meeting on Thursday 28, make sure to make it if you want to know...</p> <p>The haXe community is having an IRC meeting on Thursday 28, make sure to make it if you want to know more about haXe and different ways you can use it !</p> <p>All details about the meeting are published here : <a href="http://haxe.org/com/meeting" class="extern">http://haxe.org/com/meeting</a></p> Playing with Sfxr http://ncannasse.fr/blog/playing_with_sfxr http://ncannasse.fr/blog/playing_with_sfxr Fri, 22 Jan 2010 16:48:51 +0100 Fri, 22 Jan 2010 16:48:51 +0100 Nicolas Cannasse Nicolas Cannasse <p>In case you don't know about it, <a href="http://www.drpetter.se/project_sfxr.html" class="extern">Sfxr</a>is a very nice library used to general sound effects, perfectly...</p> <p>In case you don't know about it, <a href="http://www.drpetter.se/project_sfxr.html" class="extern">Sfxr</a>is a very nice library used to general sound effects, perfectly suitable for independent game developers :)</p> <p>Sfxr was then ported to <a href="http://www.superflashbros.net/as3sfxr/" class="extern">AS3</a>, which was itself ported to <a href="http://www.wieringsoftware.nl/ld/sfxrhx/" class="extern">haXe</a></p> <p>I wanted to use it for one of my projects, but I was not very happy with the way it worked for Flash9 : you had to load a SWF (containing a sound and generated in-memory) each time you wanted to play a sound.</p> <p>So I modified a bit the code in order to create a SWF that contains a <code>Sfx</code> class extending which is binded to the sound data. This way you can now :</p> <ul><li>build a SWF from wave bytes</li><li>load it using <code>Loader.loadBytes</code> into a new empty <code>ApplicationDomain</code></li><li>retrieve the <code>Sfx</code> class</li><li>create a <code>flash.media.Sound</code> instance</li><li>cache it for further usage</li></ul> <p>The code uses some static data to define the AS3 class. I could have done it manually by using the <a href="http://lib.haxe.org/p/format" class="extern">haXe Format Library</a> which have full SWF+ABC support but I didn't want to add one more dependencies so did something more simple instead.</p> <p>Here's the source code for that, you can plugin it into Sfxr haXe port :</p> <pre class="haxe"><span class="kwd">static</span> <span class="kwd">var</span> AS3_DATA = &quot;s238:EAAuAAAAAAgAA1NmeAtmbGFzaC5tZWRpYQVTb3VuZAZPYmplY3QMZmxhc2guZXZlbnRzD0V2ZW50RGlzcGF0Y2hlcgUWARYDGAIWBgAFBwECBwIEBwEFBwQHAwAAAAAAAAAAAAAAAAABAQIIAwABAAAAAQIBAQQBAAMAAQEFBgPQMEcAAAEBAQYHBtAw0EkARwAAAgIBAQUX0DBlAGADMGAEMGACMGACWAAdHR1oAUcAAA&quot;; <span class="kwd">static</span> <span class="kwd">var</span> AS3_BYTES : haxe<span class="number">.</span>io<span class="number">.</span>Bytes = null; <span class="kwd">public</span> <span class="kwd">function</span> buildSWFSound<span class="op">(</span><span class="op">)</span> <span class="op">{</span> <span class="kwd">var</span> rate = <span class="kwd">switch</span><span class="op">(</span> wav_freq <span class="op">)</span> <span class="op">{</span> <span class="kwd">case</span> <span class="number">5500</span>: <span class="number">0</span>; <span class="kwd">case</span> <span class="number">11000</span>: <span class="number">1</span>; <span class="kwd">case</span> <span class="number">22000</span>: <span class="number">2</span>; <span class="kwd">case</span> <span class="number">44100</span>: <span class="number">3</span>; <span class="kwd">default</span>: <span class="kwd">throw</span> &quot;Unsupported freq &quot;+wav_freq; <span class="op">}</span>; <span class="kwd">var</span> is16Bits = <span class="kwd">switch</span><span class="op">(</span> wav_bits <span class="op">)</span> <span class="op">{</span> <span class="kwd">case</span> <span class="number">8</span>: false; <span class="kwd">case</span> <span class="number">16</span>: true; <span class="kwd">default</span>: <span class="kwd">throw</span> &quot;Unsupported bits &quot;+wav_bits; <span class="op">}</span>; <span class="kwd">var</span> stereo = stereo_pan != <span class="number">0.0</span>; <span class="kwd">var</span> wave = haxe<span class="number">.</span>io<span class="number">.</span>Bytes<span class="number">.</span>ofData<span class="op">(</span>baWave<span class="op">)</span>; <span class="kwd">var</span> swf = <span class="kwd">new</span> haxe<span class="number">.</span>io<span class="number">.</span>BytesOutput<span class="op">(</span><span class="op">)</span>; swf<span class="number">.</span>writeString<span class="op">(</span>&quot;FWS&quot;<span class="op">)</span>; swf<span class="number">.</span>writeByte<span class="op">(</span>0x09<span class="op">)</span>; <span class="comment">// version</span> <span class="kwd">var</span> o = <span class="kwd">new</span> haxe<span class="number">.</span>io<span class="number">.</span>BytesOutput<span class="op">(</span><span class="op">)</span>; <span class="kwd">for</span><span class="op">(</span> b <span class="kwd">in</span> <span class="op">[</span>0x78,0x00,0x05,0x5F,0x00,0x00,0x0F,0xA0,0x00,0x00,0x0C<span class="op">]</span> <span class="op">)</span> <span class="comment">// header</span> o<span class="number">.</span>writeByte<span class="op">(</span>b<span class="op">)</span>; o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="number">1</span><span class="op">)</span>; <span class="comment">// #frames</span> <span class="comment">// Sandbox</span> o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="op">(</span><span class="number">69</span> &lt;&lt; <span class="number">6</span><span class="op">)</span> | <span class="number">4</span><span class="op">)</span>; o<span class="number">.</span>writeUInt30<span class="op">(</span><span class="number">8</span><span class="op">)</span>; <span class="comment">// AS3</span> <span class="kwd">if</span><span class="op">(</span> AS3_BYTES == null <span class="op">)</span> AS3_BYTES = haxe<span class="number">.</span>Unserializer<span class="number">.</span>run<span class="op">(</span>AS3_DATA<span class="op">)</span>; o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="op">(</span><span class="number">72</span> &lt;&lt; <span class="number">6</span><span class="op">)</span> | <span class="number">63</span><span class="op">)</span>; o<span class="number">.</span>writeUInt30<span class="op">(</span>AS3_BYTES<span class="number">.</span>length<span class="op">)</span>; o<span class="number">.</span>write<span class="op">(</span>AS3_BYTES<span class="op">)</span>; <span class="comment">// DefineSound tag</span> o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="op">(</span><span class="number">14</span> &lt;&lt; <span class="number">6</span><span class="op">)</span> | <span class="number">63</span><span class="op">)</span>; o<span class="number">.</span>writeUInt30<span class="op">(</span><span class="number">2</span> + <span class="number">1</span> + <span class="number">4</span> + wave<span class="number">.</span>length<span class="op">)</span>; o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="number">1</span><span class="op">)</span>; <span class="comment">// sound (character) ID</span> o<span class="number">.</span>writeByte<span class="op">(</span><span class="op">(</span><span class="number">3</span> &lt;&lt; <span class="number">4</span><span class="op">)</span> | <span class="op">(</span>rate &lt;&lt; <span class="number">2</span><span class="op">)</span> | <span class="op">(</span><span class="op">(</span>is16Bits?<span class="number">1</span>:<span class="number">0</span><span class="op">)</span> &lt;&lt; <span class="number">1</span><span class="op">)</span> | <span class="op">(</span>stereo?<span class="number">1</span>:<span class="number">0</span><span class="op">)</span><span class="op">)</span>; o<span class="number">.</span>writeUInt30<span class="op">(</span>wave<span class="number">.</span>length &gt;&gt; <span class="op">(</span><span class="op">(</span>is16Bits?<span class="number">1</span>:<span class="number">0</span><span class="op">)</span> + <span class="op">(</span>stereo?<span class="number">1</span>:<span class="number">0</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>; <span class="comment">// samples</span> o<span class="number">.</span>write<span class="op">(</span>wave<span class="op">)</span>; <span class="comment">// data</span> <span class="comment">// SymbolClass</span> <span class="kwd">var</span> cname = &quot;Sfx&quot;; o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="op">(</span><span class="number">76</span> &lt;&lt; <span class="number">6</span><span class="op">)</span> | <span class="op">(</span><span class="number">2</span> + <span class="number">2</span> + cname<span class="number">.</span>length + <span class="number">1</span><span class="op">)</span><span class="op">)</span>; o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="number">1</span><span class="op">)</span>; <span class="comment">// 1 class</span> o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="number">1</span><span class="op">)</span>; <span class="comment">// sound ID</span> o<span class="number">.</span>writeString<span class="op">(</span>cname<span class="op">)</span>; o<span class="number">.</span>writeByte<span class="op">(</span><span class="number">0</span><span class="op">)</span>; <span class="comment">// ShowFrame</span> o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="op">(</span><span class="number">1</span> &lt;&lt; <span class="number">6</span><span class="op">)</span> | <span class="number">0</span><span class="op">)</span>; <span class="comment">// end tag</span> o<span class="number">.</span>writeUInt16<span class="op">(</span><span class="number">0</span><span class="op">)</span>; <span class="comment">// finalize</span> <span class="kwd">var</span> swfbytes = o<span class="number">.</span>getBytes<span class="op">(</span><span class="op">)</span>; swf<span class="number">.</span>writeUInt30<span class="op">(</span> swfbytes<span class="number">.</span>length + <span class="number">8</span> <span class="op">)</span>; <span class="comment">// filesize</span> swf<span class="number">.</span>write<span class="op">(</span>swfbytes<span class="op">)</span>; <span class="kwd">return</span> swf<span class="number">.</span>getBytes<span class="op">(</span><span class="op">)</span>; <span class="op">}</span> #<span class="kwd">if</span> flash9 <span class="kwd">static</span> <span class="kwd">var</span> cache = <span class="kwd">new</span> <span class="type">Hash</span>&lt;flash<span class="number">.</span>media<span class="number">.</span>Sound&gt;<span class="op">(</span><span class="op">)</span>; <span class="kwd">static</span> <span class="kwd">var</span> pendingLoaders = <span class="kwd">new</span> <span class="type">List</span><span class="op">(</span><span class="op">)</span>; <span class="kwd">public</span> <span class="kwd">static</span> <span class="kwd">function</span> play<span class="op">(</span> settings : <span class="type">String</span>, ?delay : <span class="type">Float</span> = <span class="number">0</span> <span class="op">)</span> <span class="op">{</span> <span class="kwd">var</span> sound = cache<span class="number">.</span>get<span class="op">(</span>settings<span class="op">)</span>; <span class="kwd">if</span><span class="op">(</span> sound != null <span class="op">)</span> <span class="op">{</span> sound<span class="number">.</span>play<span class="op">(</span>delay<span class="op">)</span>; <span class="kwd">return</span>; <span class="op">}</span> <span class="kwd">var</span> s = <span class="kwd">new</span> Sfxr<span class="op">(</span><span class="op">)</span>; s<span class="number">.</span>setSettingsString<span class="op">(</span>settings<span class="op">)</span>; s<span class="number">.</span>generate<span class="op">(</span><span class="op">)</span>; <span class="kwd">var</span> timer = haxe<span class="number">.</span>Timer<span class="number">.</span>stamp<span class="op">(</span><span class="op">)</span>; <span class="kwd">var</span> l = <span class="kwd">new</span> flash<span class="number">.</span>display<span class="number">.</span>Loader<span class="op">(</span><span class="op">)</span>; pendingLoaders<span class="number">.</span>add<span class="op">(</span>l<span class="op">)</span>; <span class="kwd">var</span> domain = <span class="kwd">new</span> flash<span class="number">.</span>system<span class="number">.</span>ApplicationDomain<span class="op">(</span><span class="op">)</span>; l<span class="number">.</span>contentLoaderInfo<span class="number">.</span>addEventListener<span class="op">(</span>flash<span class="number">.</span>events<span class="number">.</span>Event<span class="number">.</span>INIT,<span class="kwd">function</span><span class="op">(</span>_<span class="op">)</span> <span class="op">{</span> pendingLoaders<span class="number">.</span>remove<span class="op">(</span>l<span class="op">)</span>; <span class="kwd">var</span> cl : <span class="type">Class</span>&lt;flash<span class="number">.</span>media<span class="number">.</span>Sound&gt; = domain<span class="number">.</span>getDefinition<span class="op">(</span>&quot;Sfx&quot;<span class="op">)</span>; cache<span class="number">.</span>set<span class="op">(</span>settings,<span class="type">Type</span>.createInstance<span class="op">(</span>cl,<span class="op">[</span><span class="op">]</span><span class="op">)</span><span class="op">)</span>; delay -= haxe<span class="number">.</span>Timer<span class="number">.</span>stamp<span class="op">(</span><span class="op">)</span> - timer; <span class="kwd">if</span><span class="op">(</span> delay &lt; <span class="number">0</span> <span class="op">)</span> delay = <span class="number">0</span>; play<span class="op">(</span>settings,delay<span class="op">)</span>; <span class="op">}</span><span class="op">)</span>; l<span class="number">.</span>loadBytes<span class="op">(</span>s<span class="number">.</span>buildSWFSound<span class="op">(</span><span class="op">)</span>.getData<span class="op">(</span><span class="op">)</span>,<span class="kwd">new</span> flash<span class="number">.</span>system<span class="number">.</span>LoaderContext<span class="op">(</span>null,domain<span class="op">)</span><span class="op">)</span>; <span class="op">}</span> #end</pre><br/> Getting Some Numbers http://ncannasse.fr/blog/getting_some_numbers http://ncannasse.fr/blog/getting_some_numbers Thu, 21 Jan 2010 00:00:33 +0100 Thu, 21 Jan 2010 00:00:33 +0100 Nicolas Cannasse Nicolas Cannasse <p>Some people often ask me what are the advantages of haXe in terms of speed.</p> <p>Of course, there are man...</p> <p>Some people often ask me what are the advantages of haXe in terms of speed.</p> <p>Of course, there are many runtime optimizations in haXe that make your program run faster, but one of the very important thing to me is also the speed of the compiler. Compiling quickly help you to test some minor changes more often, to find and fix errors faster, and prevent you from losing your concentration and your time waiting for the compiler to be done with its work.</p> <p>So what about comparing haXe and AS3 compilers speed ?</p> <p>First, haXe starts with an obvious disadvantage : because it has <em>type inference</em>, <em>structural subtyping</em> and <em>generics</em>, the compiler needs to perform much more type checks that in more classical type system such as AS3 one.</p> <p>But let's see how it rates anyway.</p> <p>I tried the following : compiling the whole <a href="http://code.google.com/p/hxformat" class="extern">hx-format</a> library, which is 64 files / 10.000 lines / 300KB of haXe to Flash9. Here's the commandline for that :</p> <pre>time haxe -swf9 format.swf -cp hxformat/tests/all All.hx</pre> <p>On my QuadCore (haXe compiler does not yet use multicores, that's something we need to fix btw) the command run in <code>0.31</code> seconds which is a decent enough.</p> <p>Now, I'm generating the corresponding AS3 output by using :</p> <pre>haxe -as3 format_as3 -cp hxformat/tests/all All.hx</pre> <p>(a small fix was needed in <code>format.amf.Reader</code> since some expression is not accepted by AS3 generator, but well...)</p> <p>Then here we go with the AS3 compilation. This was actually a bit hard, because I found that the <code>format.swf.Namespace</code> class is actually a reserved name, so had to do a bit of renaming here and there, then the <code>mxmlc</code> compiler crashed when compiling <code>format.mp3.MPEG</code> (but maybe I'm not up-to-date), and I had to recreate a <code>All.as</code> file that would ensure that all files will get compiled (since <code>import</code> in AS3 is <em>lazy</em> while it's not in haXe), and so some other minor fixes. Took me 15 minutes but I was able to compile everything except <code>format.mp3</code> package.</p> <p>So at last here we go :</p> <pre>mxmlc --output all.swf -compiler.optimize All.as</pre> <p>Took... 3.3 seconds on my QuadCore</p> <p>So, even if we take out something like 1 second for JVM startup (<code>mxmlc</code> is Java) then we still have haXe which is... <b>7x faster</b> than <code>mxmlc</code> ?</p> <p>Now, that's just a benchmark, I would be happy if other people could try the same with their own project to see if I'm accurate enough or not, but this seems to confirm that indeed, haXe is fast !</p> <p>(anybody who remember <a href="http://mtasc.org" class="extern">no more coffee break while compiling</a> ?)</p>