<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Game Haxe &#187; nme</title>
	<atom:link href="http://gamehaxe.com/category/nme/feed/" rel="self" type="application/rss+xml" />
	<link>http://gamehaxe.com</link>
	<description>Experimenting with Web Game Development</description>
	<lastBuildDate>Fri, 17 Jun 2011 01:24:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>NME From Scratch</title>
		<link>http://gamehaxe.com/2011/04/05/nme-from-scratch/</link>
		<comments>http://gamehaxe.com/2011/04/05/nme-from-scratch/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 16:37:26 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[neko]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[Haxe]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=386</guid>
		<description><![CDATA[Part 1 &#8211; Get The Basics Going I&#8217;ve just got a shiny new computer at home &#8211; nothing installed. So it seems like a good chance to go through exactly what it takes to get and NME sample up and &#8230; <a href="http://gamehaxe.com/2011/04/05/nme-from-scratch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Part 1 &#8211; Get The Basics Going</h1>
<p>I&#8217;ve just got a shiny new computer at home &#8211; nothing installed.  So it seems like a good chance to go through exactly what it takes to get and NME sample up and running on a new Windows 7 box.</p>
<p><em>8:20pm</em> For starters, I&#8217;ll need a c++ compiler, so first thing is to start the MSVC 2010 Express downloading: <a href="http://www.microsoft.com/express/Downloads/#2010-Visual-CPP">2010-Visual-CPP</a>.</p>
<p><em>8:25pm</em> OK &#8211; I&#8217;ve signed my rights away and that is downloading.  The next thing I&#8217;ll need is haxe.  It is easy to install from <a href="http://haxe.org/download">here</a>.</p>
<p><em>8:28pm</em> Haxe 2.07, neko 1.81 downloaded and installed.  Windows complained that it might not have installed correctly, but this is just because the exe had &#8220;installer&#8221; in the name, and did not write an &#8220;uninstall&#8221; entry.</p>
<p>Test: Start a &#8220;<strong>cmd</strong>&#8221; prompt by clicking on the Windows start circle and type &#8220;<strong>cmd</strong>[Enter]&#8221; into the search box.  And in this box, type &#8220;<strong>haxe</strong> [Enter]&#8220;. I am now rewarded with the haxe help message.</p>
<p><em>8:35pm</em> Visual C++ Express in successfully installed.<br />
Test:  Start up a new cmd shell, and type &#8220;<strong>cl</strong>&#8220;.  This does not work because the exe can&#8217;t be found in my path.  But here is the trick.  Type <strong>&#8220;c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat&#8221;</strong> at the prompt (note:include the quotes!), and get the message &#8220;Setting environment for using Microsoft Visual Studio 2010 x86 tools.&#8221;.  Now &#8220;<strong>cl</strong>&#8221; is rewarded with the Microsoft banner.</p>
<p><em>8:41pm</em>  I&#8217;m on a bit of a roll here, so I&#8217;ll see if I can get an haxe project going.  As I said, I have nothing installed, so I&#8217;ll go old-school.  First thing is to make a directory.  The cmd prompt starts in my home directory (c:\Users\Hugh), and I will make a directory:<br />
<strong>mkdir projects<br />
cd projects<br />
mkdir hello<br />
cd hello</strong><br />
And now, do the best I can:<br />
<strong>notepad.exe Hello.hx</strong>  (yes I do want to create the file)<br />
<code>
<pre>
class Hello
{
  public static function main()
  {
     trace("Hello!");
  }
}
</pre>
<p></code><br />
And switch back to the cmd prompt:<br />
<strong>haxe -main Hello -neko hello.n<br />
neko hello.n</strong><br />
Hello.hx:5: Hello!</p>
<p>Woo Hoo! <em>8:48pm</em> and I&#8217;ve run my own program.</p>
<p>Now lets get even more adventurous, and try a c++ example.  Trying:<br />
<strong>haxe -main Hello -cpp bin</strong><br />
Tells me that &#8220;Project hxcpp is not installed&#8221; &#8211; so let&#8217;s install it:<br />
<strong>haxelib install hxcpp</strong><br />
And try again:<br />
<strong>haxe -main Hello -cpp bin</strong><br />
And test:<br />
<strong>bin\Hello.exe</strong><br />
<em>8:43pm</em>, I have my first hxcpp prgram working!</p>
<p>Now, try for some graphics:<br />
<strong>haxelib intall nme</strong><br />
and start a new project:<br />
<strong>cd ..<br />
mkdir graphics1<br />
cd graphics1<br />
copy &#8220;c:\Motion-Twin\haxe\lib\nme\2,0,1\samples\02-Text\Sample.hx&#8221;<br />
haxe -main Sample -cpp bin -lib nme<br />
bin\Sample.exe</strong></p>
<p><em>9:05pm</em> And there it is. Haxe, neko, hxcpp, nme VC2010 installed and run in 40 minutes, including this write up.</p>
<h1>Part 2 &#8211; Compile NME From Source</h2>
<p>Well, that went much better than I expected, so I will now attempt some bleeding-edge stuff.  The version on NME used above is old, and I have no one to blame but myself.  My intentions are to do a release soon, but I just have not got my finger out.  Which leave me with the option of compiling NME from source if I want the latest features.</p>
<p>First thing, is to create a place where I can download various bits of source code for compiling.  I&#8217;m going to put it a &#8220;e:\code.google&#8221;, because my C drive is a fast SSD, and has limited room.</p>
<p><strong>e:<br />
mkdir code.google<br />
cd code.google</strong></p>
<p>Following the instructions from the <a href="http://code.google.com/p/nekonme/source/checkout">source page</a>, but changing the name, I can get a copy with:<br />
<strong>svn checkout http://nekonme.googlecode.com/svn/trunk/ nme</strong><br />
- if only I had svn installed. So first install this, I&#8217;ll be using <a href="http://sourceforge.net/projects/win32svn/">this version</a>. Once installed, I have to restart the cmd prompt and do the vsvars32.bat thing again.  Now when I try again, I get the required files.  There is also a companion project to go with NME, and that is the &#8220;sdl-static&#8221; project, which contains libraries required by NME.  To get this, simply do:<br />
<strong>svn checkout http://sdl-static.googlecode.com/svn/trunk/ sdl-static</strong><br />
This takes a while&#8230;.</p>
<p>Time to build -<br />
<strong>cd nme\project<br />
haxelib run hxcpp Build.xml</strong><br />
The &#8220;haxelib&#8221; tool looks for a file called &#8220;run.n&#8221; in an installed haxe library and runs it.  In the hxcpp project, the run.n file gathers compiler options to build the haxe output. This same program can be used to build other projects &#8211; including the NME project.  Unfortunately, compiling NME like this gives the error &#8221; cannot open input file &#8216;ddraw.lib&#8217;&#8221;.  This is because the VC express install does not have all the required system support files.  This file can be found in the &#8220;DirectX SDK&#8221;, and I&#8217;ll be using the <a href="http://msdn.microsoft.com/en-us/directx/aa937788">June 2010 version</a>.  This is a huge file, so it will take a while.  If you think it is a lot of effort for a tiny lib, then you are right.</p>
<p><em>10:10pm</em> and the download has finished.  I have chosen to install it in &#8220;e:\SDKs\Microsoft DirectX SDK (June 2010)&#8221;, because I&#8217;m trying not to put crap on my C drive, and I will be installing quite a few SDKs, and it is nice to have them all together.</p>
<p>This does not immediately fix the problem, because the NME project does not know where I installed it.  This is where the per-machine hxcpp config comes in.</p>
<p>Following the instructions in BuildCommon.xml, I create a file in &#8220;C:\Users\Hugh&#8221; called &#8220;.hxcpp_config.xml&#8221;, and put the following in it:</p>
<p><code></p>
<pre>
&lt;xml>
  &lt;section id="exes">
     &lt;linker id="dll" if="windows">
        &lt;flag value = "-libpath:e:\SDKs\Microsoft DirectX SDK (June 2010)\Lib\x86"/>
     &lt;/linker>
  &lt;/section>
&lt;/xml>
</pre>
<p></code></p>
<p>Oh crikey! Looks like Microsoft in their wisdom have dropped support for this ddraw.lib, and I&#8217;m currently using a version of SDL that needs it! It&#8217;s OK, problem solved &#8211; I&#8217;ve added it to the NME project, but you still need the SDK for dxguid.lib, which I guess I should also add.</p>
<p>Anyhow, after a long delay, at <em>10:30pm</em> I have NME building!</p>
<p>Now, going back to the original graphics1 example, the first thing to do is tell haxe to use our SVN haxe code instead of the 2.0.1 dowloaded from haxelib.  This is done via:<br />
<strong>haxelib dev nme e:/code.google/nme</strong></p>
<p>Then build &#038; test:<br />
<strong>haxe -main Sample -cpp bin -lib nme<br />
bin\Sample.exe</strong></p>
<p>Which works as before.  But now we can test some of the new features in NME.  First get the new sample, and the new associated project file:<br />
<strong>copy e:\code.google\nme\samples\02-Text\Sample.hx .<br />
copy e:\code.google\nme\samples\02-Text\Sample.nmml .</strong></p>
<p>Then you can use the NME build tool, with the command &#8220;test&#8221; (which is &#8220;build&#8221; and &#8220;run&#8221;) on the Sample.nmml project file, and for the target &#8220;neko&#8221;.<br />
<strong>haxelib run nme test Sample.nmml neko</strong><br />
And you can see the result.  Then you can test for cpp:<br />
<strong>haxelib run nme test Sample.nmml cpp</strong></p>
<p>So it&#8217;s now <em>10:45pm</em> (had to catch the end of &#8220;Dexter&#8221;) and I&#8217;ve successfully compiled the latest version of NME and tested the new project feature.</p>
<h2>Part 3 &#8211; Android</h2>
<p>Things seem to still be going well, so I&#8217;m going to take one more step &#8211; android (spoiler &#8211; this is going to take longer than expected).  First thing to so is install the <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">Java Development Kit</a>. (NOTE: Install the &#8220;windows&#8221; version, not the &#8220;x64&#8243; version) Then, the <a href="http://developer.android.com/sdk/index.html">android SDK</a>.<br />
I installed java JRE and JDK in my SDK directory, but Google&#8217;s (always painful) build tools seem to think I have not installed java, even though it works from the cmd prompt.  Thank guys. So I&#8217;ve uninstalled it, and reinstalled the JRE in the default location, and now it seems happy.  The Android SDK download is just the start &#8211; it now runs and downloads a whole bunch more.  This looks like it may take some time&#8230;</p>
<p>I may as well get on with <a href="http://developer.android.com/sdk/ndk/index.html">downloading the NDK</a> too.   And while I wait for those I&#8217;ll get my phone ADB USB drivers installed.  My HTC phone actually installs the drivers when I install HTCSync, found on my sdcard that was shipped with it.<br />
<em><strong>EDIT</strong>: The android ndk r5b still has issues with exceptions/c++.  However, these can be solved by dropping <a href="http://gamehaxe.com/wp-content/android/libstdc++.a">this version of libstdc++.a</a> from the Crystax r4 distribution over the top of sources/cxx-stl/gnu-libstdc++/libs/armeabi/libstdc++.a in your downloaded ndk.  If google ever manage to write a good build system, they might end up being a successful company.</em></p>
<p>The Google build tools also require <a href="http://www.cygwin.com/install.html">the &#8220;Cygwin&#8221; utilities</a>, so install these too.</p>
<p>Finally, we will need a new version of hxcpp, which we can get with:<br />
<strong>e:<br />
svn checkout http://hxcpp.googlecode.com/svn/trunk/ hxcpp<br />
haxelib dev hxcpp e:\code.google\hxcpp</strong></p>
<p><em>11:45pm</em>, I have finally downloaded and installed the Android prerequisites (I think) but will give up now.</p>
<p><em>Next day</em> &#8211; Here we go again.  Now to use the google android NDK, you need to have the cygwin dlls in your exe path.  To change the path, right click in the &#8220;Computer&#8221; shortcut in the start menu, and choose &#8220;properties&#8221;, then on the left &#8220;Advance system settings&#8221;, then the &#8220;Environment Variables&#8221; button and scroll through the top bit for &#8220;PATH&#8221; and click &#8220;edit&#8221;.  This already has haxe and neko in it, so we add the cygwin:<br />
<strong>%HAXEPATH%;%NEKO_INSTPATH%;e:\SDKs\cygwin\bin</strong><br />
Now restart the cmd prompt, and typing &#8220;<strong>ls</strong>&#8221; should work.<br />
And one more thing &#8211; in lieu of using &#8220;eclipse&#8221; for java building (which I just can&#8217;t stand &#8211; don&#8217;t get me started), the google tools need the <a href="http://ant.apache.org/bindownload.cgi">&#8220;ant&#8221; program</a>, which you install by unzipping somewhere.</p>
<p>Tell the build system where we installed these things.</p>
<p><strong>set ANT_HOME=e:/SDKs/ant<br />
set ANDROID_SDK=e:\SDKs\android-sdk<br />
set ANDROID_NDK_ROOT=e:\SDKs\android-ndk<br />
set JAVA_HOME=e:\SDKs\Java\jdk1.6.0_24</strong></p>
<p>And rebuild nme, like before, except that the &#8220;obj&#8221; directory should be removed first, because I have not yet allowed 2 compilers to be running at the same time.<br />
<strong>haxelib run hxcpp Build.xml -Dandroid</strong></p>
<p>Now, back in the original directory, we can build + run for android:<br />
<strong>haxelib run nme test Sample.nmml android</strong></p>
<p>Which, finally, works! You can terminate the debug log with control-c.</p>
<p>So, an awful lot of set up, but subsequent projects should only be a single line.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2011/04/05/nme-from-scratch/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>NME Font Rendering</title>
		<link>http://gamehaxe.com/2011/03/28/nme-font-rendering/</link>
		<comments>http://gamehaxe.com/2011/03/28/nme-font-rendering/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 13:49:30 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[Result]]></category>
		<category><![CDATA[AA]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=359</guid>
		<description><![CDATA[I notice FreeType has a new version out, which has some reasonable changes since a key patent has expired. Version 2.3.9, Default Version 2.3.9, AutoHinting Version 2.4.4, Default Version 2.4.4, AutoHinting Flash (Mac) GDI Threshold (Current) GDI AA GDI AA &#8230; <a href="http://gamehaxe.com/2011/03/28/nme-font-rendering/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I notice FreeType has a new version out, which has some reasonable changes since a key patent has expired.</p>
<table style="vertical-align=middle;">
<tr>
<td >Version 2.3.9, Default</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/FT-Default.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/FT-Default.png" alt="" title="FT-Default" width="240" height="120" class="alignnone size-full wp-image-360" /></a>
</td>
</tr>
<tr valign="center">
<td >Version 2.3.9, AutoHinting</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/FT-AutoHint.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/FT-AutoHint.png" alt="" title="FT-AutoHint" width="240" height="120" class="alignnone size-full wp-image-361" /></a>
</td>
</tr>
<tr>
<td>Version 2.4.4, Default</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/FT-2.2.4-Default.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/FT-2.2.4-Default.png" alt="" title="FT-2.2.4-Default" width="240" height="120" class="alignnone size-full wp-image-362" /></a>
</td>
</tr>
<tr>
<td>Version 2.4.4, AutoHinting</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/FT-2.2.4-AutoHint.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/FT-2.2.4-AutoHint.png" alt="" title="FT-2.2.4-AutoHint" width="240" height="120" class="alignnone size-full wp-image-363" /></a>
</td>
</tr>
<tr>
<td>Flash  (Mac)</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/MacFlash.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/MacFlash.png" alt="" title="MacFlash" width="240" height="120" class="alignnone size-full wp-image-364" /></a>
</td>
</tr>
<tr>
<td>GDI Threshold (Current)</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/GDI_threshold.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/GDI_threshold.png" alt="" title="GDI_threshold" width="240" height="120" class="alignnone size-full wp-image-377" /></a>
</td>
</tr>
<tr>
<td>GDI AA</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/GDI_AA_raw.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/GDI_AA_raw.png" alt="" title="GDI_AA_raw" width="240" height="120" class="alignnone size-full wp-image-378" /></a>
</td>
</tr>
<tr>
<td>GDI AA + Gamma</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/GDI_AA_gamma.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/GDI_AA_gamma.png" alt="" title="GDI_AA_gamma" width="240" height="120" class="alignnone size-full wp-image-379" /></a>
</td>
</tr>
<tr>
<td>Flash  (Windows)</td>
<td>
<a href="http://gamehaxe.com/wp-content/uploads/2011/03/WindowsFlash.png"><img src="http://gamehaxe.com/wp-content/uploads/2011/03/WindowsFlash.png" alt="" title="WindowsFlash" width="240" height="120" class="alignnone size-full wp-image-380" /></a>
</td>
</tr>
</table>
<p>So a few observations: The &#8220;Default Hinting&#8221; has changed quite a bit for TrueType fonts in the latest version.  I think this code is what the expired patent related to, allowing the font-specific hinting data to be used.  The &#8220;AutoHinting&#8221; mode is based on font-independent logic built into FreeType. The Flash renderer uses component based sub-pixel rendering, using RGB components to get finer details.  The font also looks a bit &#8220;fatter&#8221;.</p>
<p>Currently NME uses a single set of bitmaps for the fonts, which must be used for all colours.  This means that component based sub-pixel rendering is not really an option.  However, it may be possible to sort something out (at the expense of more memory) if the need really arises.  But also note, this is counter-productive in landscape mode on mobile devices.</p>
<p>On windows, NME currently uses GDI fonts with a threshold.  I like the look of this (I spend most of my time on windows) for the small fonts, but it looks pretty bad on the larger fonts.  Particularly note the exactly 1-pixel wide vertical lines in the &#8220;H&#8221; and the &#8220;l&#8221;, which I like. The larger fonts look much better with anti-aliasing on.  However, windows applies some kind of gamma-correction when rendering fonts, and you get quite a different look for black-on-white and white-on-black.  To work around this, I have applied a lookup-table to get a bitmap that will work for both light and dark.</p>
<p>Finally notice the windows flash renderer does not use AA with this swf (although the Mac version did).</p>
<p>In the next version, I will change windows over to use GDI + AA + Gamma.  It is possible to use FreeType, but I think the font is slightly less readable at the smaller sizes.  What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2011/03/28/nme-font-rendering/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android + HXCPP &#8211; a Quickstart Guide</title>
		<link>http://gamehaxe.com/2010/09/30/android-hxcpp-a-quickstart-guide/</link>
		<comments>http://gamehaxe.com/2010/09/30/android-hxcpp-a-quickstart-guide/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 06:18:55 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[Haxe]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=341</guid>
		<description><![CDATA[After having some success with making an Xcode template, I thought it would be relatively easy make something similar for eclipse and Android. However, there was nothing but pain for me when I tried, so instead I&#8217;ve decided to write &#8230; <a href="http://gamehaxe.com/2010/09/30/android-hxcpp-a-quickstart-guide/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After having some success with making an Xcode template, I thought it would be relatively easy make something similar for eclipse and Android.  However, there was nothing but pain for me when I tried, so instead I&#8217;ve decided to write this guide.</p>
<h3>Prerequisites</h3>
<p>There are quite a few prerequisites you need to organize before you can get things going.  Android allows building from Windows, Mac and Linux.  The procedures are quite similar, except that Windows requires some messing about with Cygwin binaries.  The method described here avoids most of the Cygwin pain \- and the google make sytem pain \- by avoiding the google make sysem altogether.</p>
<ul>
<li>Download and install the <a href="http://developer.android.com/sdk/index.html">Android SDK</a>.  This is the Java tools and libraries required for building and debugging byte-code applications.
<li>
<li> Download and install eclipse IDE.  This is the IDE that runs the SDK &#8211; follow the instructions on the Android SDK page and install the Android plugins too.</li>
<li> Install the USB drivers for your device (if required).  For my device (HTC Legend) I found the drivers on the phone itself by using it as a thumb drive.
</ul>
<p>You should now be in a position to build some sample (byte-code) applications for your device.</p>
<ul>
<li>Download the Android Native Development Kit.  This allows you to build binary code for your device.  Now for HXCPP, it is <b>very important</b> to download the latest build provided at <a href="http://www.crystax.net/android/ndk.php">Crystax.net</a>, which is a build done by a generous community member that corrects some of the glaring omissions of the official build, namely RTTI and exceptions.  If it is all the same to you, extract it to c:/tools/android-ndk for Windows, and ~/tools/android-ndk for other systems, and this will make the remaining instructions easier.
</li>
<li> Currenly on Windows, you need the svn version of HXCPP (slightly newer that 2.06.1) which has some include path fixes.  See the instructions at <a href="http://code.google.com/p/hxcpp/">http://code.google.com/p/hxcpp/</a> for getting the latest version.</li>
<li> Also on windows, you need the Cygwin dlls in your path.  One way to do this is to install the whole Cygwin toolchain and put it in your path.  The other way so to drop the two dlls from <a href="/wp-content/android/cygwin-extra.tgz">cygwin-extra.tgz</a> into the ndk binary directory, ie c:/tools/android-ndk/build/prebuilt/windows/arm-eabi-4.4.0/bin.</li>
</ul>
<h3>Project structure</h3>
<p> An android project consists several  components that all work together.</p>
<ul>
<li> Java Code.  The Java code provided in the sample project comes from a couple of places.  Because the project is graphics based, the copy NME Java code is included.  If the version of NME increases, it may be desirable to update the NME code, either by copying the new code in, or instead linking to the NME code directly.  Also, the HXCPP bootstrap Java code is included along with a small Activity wrapper file.</li>
<li> Native code.  The shared object files provide native code for running on the device.  These include the standard libraries, the NME library and the haxe code compiled with hxcpp.</li>
<li>AndroidManifest.xml. This controls how your application is deployed, and quite a few things can be done with this file.  It is best to consult the Android documentation about what can be done here.
<li>Resources &#038; Assets.  These can be useful if you want to add standard menus or other GUI elements to your application.
</ul>
<p>The basic workflow starts by making a change to your haxe source files.  You then compile the haxe code to Android cpp, which is in turn is compiled to an android shared object.  This .so file is then copied to the libs/armeabi directory in the project.  Because eclipse does not recognize a change to the shared objects as a important update, it is then necessary to touch one of the Java files so that eclipse rebuilds the project.  These steps are handled by the build_haxe batch/shell scripts provided with the project, so all you should have to do is change the code and run the script.  Then, press the &#8220;play&#8221; button in eclipse(the first time you do this, you may need to specify Run-As Android Project) and your application should launch.</p>
<p>The haxe code included in the sample directory uses a fixed class name, AndroidMain, as the bootstrap point for building the haxe shared object, libAndroidMain.so.  By fixing these names, the build script is simplified. I encourage you to put your main code for the application outside the provided project directory, and edit the AndroidMain.hx and build.hxml files to point to this external application code.  This will help with cross-platform development, and keep the boiler-plate code separate from your precious source code.</p>
<h3>Creating a New Project</h3>
<p>I could not find a very nice way to make a project template, so this is what I&#8217;ve come up with.  First, download and extract the example project, <a href="/wp-content/android/android-2.06.1.tgz">android-2.06.1.tgz</a>.  You may like to rename the parent directory from android-2.06 to something more meaningful at this stage.</p>
<p>At this point, you should be able to build the sample haxe code using the build-scripts provided.  This requires your prerequisite installations to be good, so it is worth testing.  If you have downloaded the android-ndk to a different location, you can edit the appropriate build script to reflect this.  You will need the latest NME code from haxelib.  Windows users may also need the svn version of HXCPP.</p>
<p>So that all worked?  Congratulations, your system is set up for development.</p>
<p>Next, fire up eclipse, and create a &#8220;File &#8211; New Project..&#8221;, then select &#8220;Android Project&#8221;, then select  &#8220;Create project from existing source&#8221;, and browse to your newly created directory.  You will notice that down the bottom of the Dialog, the properties are filled out with names from the sample project &#8211; we will change these next.  Once you select &#8220;Finish&#8221;, your project should be created, and ready to run on your device.</p>
<p>The project and package names are tied into Java and Android naming conventions, as well as the Android manifest, and can be difficult to budge.  It is easiest to use the eclipse Refactor-Rename menu option to change the name from &#8220;MyActivity&#8221; to something more appropriate for you, say &#8220;CircleDisplay&#8221;.  Then in the source tree under &#8220;src&#8221;, there is a file in com.company called &#8220;MyActivity.Java&#8221;.  Select this, and use the menu option to change its name to &#8220;CircleDisplay&#8221; too.  Similarly, select the &#8220;com.company&#8221; and change this to something else, in my case &#8220;com.gamehaxe&#8221; (select preview and agree to everything).  There is one final change required &#8211; the refactor option misses a reference in the AndroidManifest.xml because it starts with a period.  Double click this and in the &#8220;AndroidManifest.xml&#8221; tab, change the &#8220;.MyActivity&#8221; to &#8220;.CircleDisplay&#8221;.</p>
<p>It is important to rename these items because it effects how your application is ultimately stored in the device.</p>
<p>So now you should be good to go &#8211; press the play button and select &#8220;Android Project&#8221;.</p>
<p>There are quite a few things that can go wrong with so many things to install, so I&#8217;ve got my fingers crossed for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2010/09/30/android-hxcpp-a-quickstart-guide/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Minor Updates</title>
		<link>http://gamehaxe.com/2010/09/12/minor-updates/</link>
		<comments>http://gamehaxe.com/2010/09/12/minor-updates/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 16:14:25 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[nme]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=336</guid>
		<description><![CDATA[I have just released a few minor updates to nme + hxcpp, which you can find on haxelib. These are relatively small \- just pushing out a few fixes for some bugs that have been reported. In most cases the &#8230; <a href="http://gamehaxe.com/2010/09/12/minor-updates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have just released a few minor updates to nme + hxcpp, which you can find on haxelib.  These are relatively small \- just pushing out a few fixes for some bugs that have been reported.  In most cases the bug reports we accompanied by a fix \- you&#8217;ve gotta love open source.  The <a href="http://gamehaxe.com/wp-content/xcode/NMETemplate-2.0.1.tgz">iPhone/Xcode template has also been updated</a>, you may need to follow the instructions in the post below.</p>
<p>There is one significant change though &#8211; the &#8220;nekoapi.dll&#8221; file that is used for compatibility between hxcpp binaries (ie, NME) and neko has changed its extension to &#8220;ndll&#8221; so that neko can communicate directly with it.  This allows the String instances created externally to be &#8220;blessed&#8221; as haxe strings without having to call nekoToHaxe on them, and therefore methods such as substr will work.</p>
<p>The other change of note is that I removed the libfreetype code from the iPhone target, and used native font rendering instead.  Let me know if this breaks anything.  One side effect is that the default font will now be system dependent, with the iPhone getting its usual font.  I will also have to have a good look at the font render quality &#8211; freetype may have a little bit better sub-pixel sharpness.</p>
<p>There was a bug in the 2.06 haxe distribution when writing files.  I have fixed this by putting an override in hxcpp, which you can access with the command line options: &#8220;-lib hxcpp&#8221;.  I have also folded this change into haxe svn, so you will not need to do this in 2.07.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2010/09/12/minor-updates/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>New Releases!</title>
		<link>http://gamehaxe.com/2010/08/19/new-release/</link>
		<comments>http://gamehaxe.com/2010/08/19/new-release/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 15:27:28 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[neash]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=326</guid>
		<description><![CDATA[Finally, I&#8217;ve managed to make a few more releases. Namely, HXCPP 2.06 and NME 2.0. HXCPP can be downloaded via &#8220;haxelib&#8221;, and works with the new 2.06 version of haxe. This release contains many bug fixes and optimizations. Also, when &#8230; <a href="http://gamehaxe.com/2010/08/19/new-release/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Finally, I&#8217;ve managed to make a few more releases.  Namely, HXCPP 2.06 and NME 2.0.<br />
HXCPP can be downloaded via &#8220;haxelib&#8221;, and works with the new 2.06 version of haxe.  This release contains many bug fixes and optimizations.  Also, when you compile with the -debug flag, you can get additional null checks and stack dumps.<br />
NME 2 is a complete rewrite from the ground up.  Most of the logic has been moved from neash to the c++ code for optimization reasons.<br />
For NME developers this only means a couple of things:</p>
<ul>
<li> You use &#8211;remap flash=nme instead of &#8211;remap flash=neash</li>
<li> The &#8220;boot&#8221; code has changed, so you will need to follow the main line from one of the samples. </li>
<li> Improved performance! </li>
</ul>
<p>I updated my Xcode SDK, which caused a bunch of link errors linking for the simulator with the NME library.  It seems Apple have changed the &#8220;ABI&#8221; for objc (basically, broke binary compatibility).  So I must choose pre 4.0, post 4.0 or both.  I think I am going to require NME iphone simulator users to have the latest SDK &#8211; unless there are any objections?</p>
<h2>iPhone Xcode Template</h2>
<p>I finally got around to making an Xcode template for haxe compiling. <a href="http://gamehaxe.com/wp-content/xcode/NMETemplate-2.0.0.tgz">Try it out</a> and let me know if it works.  It&#8217;s my first one, so I&#8217;m open to ideas for improving it.</p>
<p>To use the template, first extract it to your developer template area, eg: /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application.<br />
Then when you create an new Xcode project, this template should show up.  You should be able to build for the simulator.</p>
<p>To build for a real device, you will need to go though the official Apple developer program, and get yourself signed up.  Then you need to get your certificates in order, and finally edit the &#8220;plist&#8221; file in the Resources folder and change the company URL to match the one you used in your certificates.</p>
<p>You can edit Main.hx code in the &#8220;haxe/src&#8221; directory, but you will probably want to locate your haxe source tree outside your project area, since we are multi-platform developers an do not  want to tie ourselves to Xcode.  To do this, you can edit the class path in the Build.xml file, and change the boot code in IPhoneMain.hx.  It is done this way so the haxe-generated library always has the same name.  If all else fails, you can have a look in the makefile, which is set up to allow building debug and release versions for iphoneos and simulator without having to change other project settings.</p>
<p>Let me know if you have any luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2010/08/19/new-release/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Android Port &#8211; Second Look</title>
		<link>http://gamehaxe.com/2010/06/29/android-port-second-look/</link>
		<comments>http://gamehaxe.com/2010/06/29/android-port-second-look/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 15:54:58 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[Result]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[Haxe]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=321</guid>
		<description><![CDATA[I have looked into some of the performance aspects of the Android port, and I&#8217;ve come to some conclusions. Firstly, after looking at the disassembly, there did not seem to be any additional code associated with exception handling, so there &#8230; <a href="http://gamehaxe.com/2010/06/29/android-port-second-look/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have looked into some of the performance aspects of the Android port, and I&#8217;ve come to some conclusions.  Firstly, after looking at the disassembly, there did not seem to be any additional code associated with exception handling, so there was no optimizing to be done there.  Secondly, the compile flags meant that software floating point operations were used, rather than the built-in hardware FPU.</p>
<p>So I added compile flags to force hardware floats, and added armv6 instructions while I was at it.  <a href="http://gamehaxe.com/wp-content/android/hxAndroid-fpu.apk">You can get the installer here</a>.</p>
<p>This gives my phone a nice 50% boost in frame-rate to about 15fps.  However, on some devices this app may fail to run.  This change brings the performance in line with iPhone performance for the simulation side of the program.  However the OpenGL seemed slower.  I guess the Qualcomm MSM 7227 does not have strong 3D acceleration \- or perhaps I am still missing something?</p>
<p>For comparison, you can test the flash version of the code <a href="http://gamehaxe.com/wp-content/android/">in this directory</a>.  I get about 6\-7 fps, which is not too far from my initial software-float based results and is quite impressive.  I&#8217;m not sure if the flash renderer is using software or hardware rendering \- maybe it&#8217;s worth a closer look to find out what it&#8217;s doing.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2010/06/29/android-port-second-look/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Android Port &#8211; First Light</title>
		<link>http://gamehaxe.com/2010/06/28/android-port-first-light/</link>
		<comments>http://gamehaxe.com/2010/06/28/android-port-first-light/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 14:23:27 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[Haxe]]></category>
		<category><![CDATA[ndk]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=309</guid>
		<description><![CDATA[I bought myself and Android (2.1) HTC Legend phone. Obviously, the first thing I wanted to do was to get haxe/NME running on it. Now the Android platform is very well setup for Java development but, unfortunately, the haxe Java &#8230; <a href="http://gamehaxe.com/2010/06/28/android-port-first-light/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I bought myself and Android (2.1) HTC Legend phone.  Obviously, the first thing I wanted to do was to get haxe/NME running on it.   Now the Android platform is very well setup for Java development but, unfortunately, the haxe Java target is not fully developed at the moment.  Luckily, there is also a &#8220;native&#8221; development kit (NDK) that allows you to run c++ code on the device using a Java bootstrap to load the code and JNI.</p>
<p>The NDK is based in the GCC toolchain, and therefore is already pretty well supported by the hxcpp haxe backend.  The problem is that the standard NDK is somewhat crippled &#8211; it does not support exceptions or the STL.  It is possible to rework the hxcpp backend to work without the STL, but removing exceptions may take a bit more work.   I managed to work around this by using a slightly modified NDK, created by a very helpful member of the comminity over at <a href="http://www.crystax.net/android/ndk-r4.php">crystax.net</a>.  In theory this should have been all that was required, however the NDK also lacks proper wchar_t support.  When I finally worked this out, it was reasonably easy to substitute a simple translation layer to fix these wide-char problems.<br />
<a href="http://gamehaxe.com/wp-content/uploads/2010/06/Android1.png"><img src="http://gamehaxe.com/wp-content/uploads/2010/06/Android1.png" alt="" title="Android1" width="480" height="320" class="alignleft size-full wp-image-312" /></a>  So far, I have only implemented the rendering API, with no interactive options.  The OpenGL ES rendering code is exactly the same as for the iPhone, except that the initial context and display surface are setup in the Java code, rather than the Objective C code.</p>
<p>Developing with haxe for the Android target requires several modules to work together.  First, you compile your haxe code as normal to a shared object &#8211; which is actually a JNI module.  This exposes a single &#8220;main&#8221; function that can be called from Java.   Your actual Android application starts with Java code, and you can setup the properties etc. from eclipse.  Ultimately this will be boilerplate code and you will only need to change the bits you need to.  This Java code then calls the haxe main function.  In the graphical/NME environment the main thing this does is dynamically load the nme native library and setup a callback for when the graphics are finally initialized.  You then return to Java code and setup a OpenGL ES context.  When this is done, a JNI call is made into the nme dynamic library, which in turn calls back into your haxe application to complete setup.  The &#8220;MainLoop&#8221; is then processed in Java, and events such as &#8220;Redraw&#8221; (and later &#8220;OnMouse&#8221; etc) are passed into the nme library, and then into the haxe application as registered &#8220;addEventListeners&#8221;.</p>
<p>So in this somewhat convoluted way, Java maintains full control of the app, and therefore correct interaction with the OS, while almost all the real work is done in the haxe code.   In the example shown here, no changes were necessary to the haxe code, and the internal garbage collection also worked without modification, so it is a pretty solid cross-platform solution.  </p>
<p> Now the bad news.  The performance is way down compared to my 2nd generation iPod touch.  This example is 10fps on the Android device, and about 24 on the iPod.  Which is strange, because the core should actually be running a bit faster.  The slowdown seems to be on both the OpenGL side, and the physics calculation side.  It should also be noted that this is a first pass, so there is quite a bit of room for improvement.  My guess is that the gcc compiler is generating significant runtime overhead per function because of the exception code.  This is what I noted while compiling for the iPhone (it was doing a pthread lock per function!) \- but in that case the penalty was only incurred in functions that actually &#8220;threw&#8221;, so I simply moved the throwing code into a separate function.  Which brings me to my second problem &#8230;</p>
<p>No easy profiling or debugging support for native code.  This is a real pain for debugging (back to &#8220;log&#8221; debugging) and the lack of profiling makes it very hard to work out what needs optimizing for the target.  I may be able to use a simple &#8220;setjump&#8221; style system for exceptions because the use of garbage collection means that there are no real destructors required for cleanup. But I would need to be sure this would help &#8211; premature optimization and all that.</p>
<p>I would also count the fact that you really need to use eclipse as an IDE as a big negative, but I think that this is just my personal dislike of the program.  I think there may ultimately be ways around this with command-line compilers etc.</p>
<p>Native compiling tools for the Android target are still in active development and moving forwards, so I&#8217;m assuming that most of these problems will be overcome eventually.  And of course, the big advantage of the Android OS is the openness \- so I can provide you with the actual application to run on your device \- <a href="http://gamehaxe.com/wp-content/android/hxAndroid.apk">give it a go</a>, and let me know if it runs for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2010/06/28/android-port-first-light/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>JavaScript &#8211; ready or not.</title>
		<link>http://gamehaxe.com/2010/05/25/javascript-ready-or-not/</link>
		<comments>http://gamehaxe.com/2010/05/25/javascript-ready-or-not/#comments</comments>
		<pubDate>Tue, 25 May 2010 16:31:49 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[neko]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[Result]]></category>
		<category><![CDATA[Haxe]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[v8]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=297</guid>
		<description><![CDATA[JavaScript Performance There have been some very promising improvements in JavaScript performance, but exactly how good is it? It turns out, that there is a pretty easy way to work this out &#8211; thanks to haxe. Haxe allows the same &#8230; <a href="http://gamehaxe.com/2010/05/25/javascript-ready-or-not/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>JavaScript Performance</h2>
<p>There have been some very promising improvements in JavaScript performance, but exactly how good is it?  It turns out, that there is a pretty easy way to work this out &#8211; thanks to <a href="http://haxe.org//">haxe</a>.</p>
<p>Haxe allows the same code base to be compile to Flash, JavaScript, neko and cpp.  The graphics is handled differently &#8211; Flash uses its plugin, JS uses canvas and neko is using the NME library, running opengl.  To compare these, I&#8217;ve chosen the Physaxe library, which is optimized for all these platforms, and can give a feeling for an app that has a computational and graphics load.</p>
<p>Into this mix, I will add another interesting option:  The V8 JS engine, running using the NME library in opengl mode.  This cross-over mode is actually quite easy to implement because of 3 stars aligning:  1. The NME library has a external interface that uses opaque handles that map very naturally to the v8::Value *.  2. The haxe compiler makes it possible to program JS without losing your mind, and all the existing library code is valid for this target. and 3:  The Google V8 JS engine has a clean API that makes it easy to embed (you would almost think they designed it that way &#8211; dispite the frugal documentation).</p>
<p>The benchmark I have chosen is the &#8220;Pentagonal Rain&#8221;, which is nice and stressful for the CPU.  You can try for yourself &#8211; use the &#8217;5&#8242; key to switch to this demo.</p>
<ul>
<li><a href="http://gamehaxe.com/wp-content/physaxe/js-web/physaxe-js.html">JavaScript Canvas</a>
<li><a href="http://gamehaxe.com/wp-content/physaxe/swf-web/physaxe-flash.html">Flash</a>
<li><a href="http://gamehaxe.com/wp-content/physaxe/physaxe-win32.zip">Win32 Binaries (Neko, V8VM, CPP-compiled)</a> (extract and drag the &#8220;.n&#8221; file onto neko.exe, or drag the &#8220;.js&#8221; onto the v8vm.exe)
</ul>
<table>
<tr>
<th>Engine</th>
<th>FPS</th>
</tr>
<tr>
<td>Neko/nme</td>
<td>9</td>
</tr>
<tr>
<td>Chrome 4.1, JS</td>
<td>11</td>
</tr>
<tr>
<td>Opera 10.5.3, JS</td>
<td>18</td>
</tr>
<tr>
<td>V8VM/nme</td>
<td>23</td>
</tr>
<tr>
<td>Flash</td>
<td>37</td>
</tr>
<tr>
<td>CPP/nme</td>
<td>130</td>
</tr>
</table>
<p>So as you can see, the V8VM option is actually quite viable as a scripting vm.  Since there is <em>a lot</em> in common between neko, v8vm and cpp haxe targets and plugin architectures, it should be relatively straight forward to switch between them.</p>
<p>The JS demo <em>can</em> run on the iPhone.  But just because you can do something, it doesn&#8217;t not mean you should \- at about 2 FPS on the title screen, I can&#8217;t imagine how slow it would run in the Pentagonal Rain demo.  And probably not great for your battery either <img src='http://gamehaxe.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2010/05/25/javascript-ready-or-not/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Quick Update</title>
		<link>http://gamehaxe.com/2009/10/15/quick-update/</link>
		<comments>http://gamehaxe.com/2009/10/15/quick-update/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 05:01:22 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[neash]]></category>
		<category><![CDATA[nme]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=235</guid>
		<description><![CDATA[Just a quick update to let you know things are still moving forwards. I have not done very much iPhone specific stuff recently, but I have been working on the graphics code base in general. The idea is to separate &#8230; <a href="http://gamehaxe.com/2009/10/15/quick-update/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a quick update to let you know things are still moving forwards.  I have not done very much iPhone specific stuff recently, but I have been working on the graphics code base in general.  The idea is to separate the graphics code from SDL (although still use SDL most of the time) to avoid GPL issues and also allow the library to be used in a wider set of applications rather than just games.  For example, inside a window in a larger desktop application, or inside Google&#8217;s Native Client plugin.  Another goal is to improve rendering speed by minimising the amount of data moved between haxe and the graphics code &#8211; this involves moving code logic from haxe into c++. I have also been looking at a few minor tweaks such as setting object widths/alphas like flash does.</p>
<p>Once this is done and moved into Neash/NME, I will fix a few of the remaining issues on the C++ backend &#8211; maybe even get to add dynamic properties to the runtime.  I would also like to spend a bit of time finishing off the internal garbage collection to make it thread-safe and run automatically &#8211; this could solve some of the problems compiling boehm-gc on various systems.</p>
<p>And, of course, I would like to write more tutorials&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2009/10/15/quick-update/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Haxe, iPhone &amp; C++ At Last</title>
		<link>http://gamehaxe.com/2009/07/28/haxe-iphone-cpp-at-last/</link>
		<comments>http://gamehaxe.com/2009/07/28/haxe-iphone-cpp-at-last/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 16:33:28 +0000</pubDate>
		<dc:creator>Huge</dc:creator>
				<category><![CDATA[hxcpp]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[neash]]></category>
		<category><![CDATA[nme]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[Haxe]]></category>

		<guid isPermaLink="false">http://gamehaxe.com/?p=206</guid>
		<description><![CDATA[Announcing first official release of c++ on haxe, including Widsows,  Mac, Linux and iPhone support. <a href="http://gamehaxe.com/2009/07/28/haxe-iphone-cpp-at-last/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Hxcpp 1.0, neash 1.0, NME 1.0</h3>
<p>The release this week of haXe version 2.0.4 officially includes c++ as a build target, for Windows, Mac, Linux and iPhone.  You can download and install from <a href="http://haxe.org/">haxe.org</a>.  In addition to the standard includes, you will need the &#8220;hxcpp&#8221; library, which can be insatlled with the included haxelib management tool.</p>
<p>Coincident with the hxcpp release, I have updated the neash and NME libraries to versions 1.0.  You can also download these via the haxelib tool too.  There are several incrental improvements, and the iPhone target has been added!</p>
<h3>Getting started with the iPhone</h3>
<p>Getting started with the iPhone is quite tricky at the moment, mainly because of the pain of setting up an Xcode project.  Also,  getting the simplest program onto the device is hard due to the code signing requirements. So if you can already get one of the existing application templates to work, you are half way there.</p>
<p>Note that this solution uses the &#8220;SDL&#8221; library, and must statically link against this.  SDL is covered by the LGPL license, and this has implications should you choose to release your software.  I am hoping to remove the LGPL restiction at a later date.</p>
<p>The binaries used here are have been compiled for the &#8220;2.2.1&#8243; iPhone SDK.  So choose this version when compiling for simulator or device.</p>
<ol>
<li> Download and install components
<ul>
<li><b>Get haxe &#038; neko:</b> Visit <a href="http://haxe.org">haxe.org</a>
<li><b>Get hxcpp:</b>  haxelib install hxcpp
<li><b>Get nme:</b>  haxelib install nme
<li><b>Get neash:</b>  haxelib install neash
<li> <b>Get the sdl-static libs for iphone:</b> I have created a project with binary builds of these.  You can get the latest builds directly from  subversion svn code at:<br />
    <a href="http://code.google.com/p/sdl-static/source/checkout">http://code.google.com/p/sdl-static/source/checkout</a>.<br />
Or get the snapshot bundle from this site and install somewhere handy:<br />
    <a href="/wp-content/uploads/sdl-static-iphone-1.0.zip">sdl-static-iphone-1.0.zip</a>
</ul>
<li> Get Xcode with iphone sdk support &#8211; visit apple.com</li>
<li>Get a Developer key (you can try simulator without it).  You will need to pay to sign up as a developer on the apple site.
</li>
<li>
 Fire up Xcode and do File > New Project.</p>
<p>    Choose <strong>iPhone OS > Application</strong>.  Here choose a &#8220;<strong>Windows-Based Application</strong>&#8221;<br />
    but infact we will use the delegate setup in the SDL code, so we will have<br />
    to delete the one created by the wizard.</p>
<p>    Select a name &#038; directory for the project.  I&#8217;m calling it &#8220;Haxe Test&#8221;.</p>
<p>    Now as it stands, you should be able to build for the Simulator and<br />
    get a lovely white screen and a program called &#8220;Haxe Test&#8221; in the simulator<br />
    start screen.</p>
<p>    Next thing is to delete(to trash) the &#8220;&#8230;AppDelegate.h&#8221; &#8220;&#8230;AppDelegate.m&#8221;,<br />
     the &#8220;Nib Files&#8221; group, Resources/MainWindow.xib and &#8220;main.m&#8221;.<br />
   Finally, select the &#8220;Haxe Test&#8221; executable (in the Targets section) and from the &#8220;Get Info&#8221; &#8211;<br />
   &#8220;Properties&#8221; tab, clear the reference to &#8220;MainWindow&#8221;.</p>
<p>     We will add replacements for these soon.</p>
</li>
<li>
 Add &#8220;main.cpp&#8221; from the NME project.<br />
    Select the top-level project folder and then use <strong>Action > Add > Existing Files</strong>.<br />
    It is  probably in <em>/usr/lib/haxe/lib/nme/1,0/ndll/iPhone/</em> or<br />
     similar depending on which version of NME you have installed.  It can be<br />
     very painful to get xcode to load from this location, unless you hit<br />
     Command-Shift-G at the &#8220;Add&#8221; dialog and type (at least some) of this filename in.<br />
    Choose to &#8220;Copy to destinations folder&#8221; so<br />
    that you can mess with it if you wish.  Note:  you need to have a cpp mainline<br />
    in order to automatically link in the correct runtime libraries.</p>
</li>
<li>
 Add the libNME.iphoneos.a and  libNME.iphonesim.a files from the haxelib NME project.<br />
    You can add them both and the linker<br />
    will select the correct on depending on your build.  They are in the same place<br />
    as main.cpp, you you should be able to use &#8220;iPhone&#8221; from the pull-down box<br />
    in the add dialog.  Probably best not to copy these files &#8211; in case you want<br />
    to change them at some stage.
</li>
<li>
 Add the whole sdl-static/lib/iPhone directory. <br />Again probably best not to copy.<br />
     I used the &#8220;Recursively create groups&#8221; option.  These will be where you stored them<br />
     in step 1.</p>
</li>
<li>
Add the whole hxcpp/bin/iPhone directory like above.<br />  Again, this will<br />
     be in a path like <em>/usr/lib/haxe/lib/hxcpp/1,0,2/bin/iPhone/</em>.
</li>
<li>
 Add the hxcpp include directory to the include path. <br /> Use the &#8220;Info&#8221; button<br />
    to get the project properties, and on the build tab, under &#8220;Search Paths&#8221;<br />
    add something like <em>/usr/lib/haxe/lib/hxcpp/1,0,2/include/</em> to  &#8220;Header Search Path&#8221;
</li>
<li> Now we are ready for the haxe code.  If you have and existing project,<br />
then you can adapt the following instructions.</p>
<p>Create a new file from Xcode (Other/Empty File]  Here I have called it &#8220;HaxeTest.hx&#8221;, and unticked the &#8220;Targets&#8221; option.  I&#8217;m prety sure there is a way to get &#8220;Haxe File&#8221; to appear as on option here &#8211; but I don&#8217;t know the details.</p>
<p>In the haxe file, enter something like (Note the window size):</p>
<p><code></p>
<pre>
import flash.display.Sprite;
import flash.display.Shape;

class HaxeTest extends Sprite
{

   public function new()
   {
      super();
      flash.Lib.current.addChild(this);

      var circle:Shape = new Shape( );
      circle.graphics.beginFill( 0xff9933 , 1 );
      circle.graphics.drawCircle( 0 , 0 , 40 );
      circle.x = 150;
      circle.y = 200;
      addChild( circle );
   }

   static public function main()
   {
      neash.Lib.mOpenGL = true;
      neash.Lib.Init("HaxeTest",320,480);
      neash.Lib.SetBackgroundColour(0x447733); 

      new HaxeTest();

      neash.Lib.ShowFPS();
      neash.Lib.Run();
   }
}
</pre>
<p></code></p>
<p>This is the &#8220;main&#8221; file for haxe, and the hxcpp compile will create a library matching<br />
this class name.</p>
<li> Set up a build script to build changes you make to your haxe files into a library.<br />
   Xcode has a few issues with a straight custom build script order due to incorrect<br />
   dependency checking.  This can be worked around by first adding a custom target.</p>
<p>   Highlight the &#8220;Targets&#8221; in the Groups &#038; Files and use the &#8220;<strong>Action > Add > New Target..</strong>&#8221;<br />
   Choose &#8220;<strong>Other > Shell Script Target</strong>&#8221; and call it something like &#8220;Compile Haxe&#8221;.<br />
   Close the pop-up and go back to the explorer.  There should be a &#8220;Run Script&#8221;<br />
    entry under the &#8220;Compile Haxe&#8221; target if you expand it out.</p>
<p>   Get info on &#8220;Run Scipt&#8221; and enter the following script</p>
<p><code></p>
<pre>
   if [ "$CURRENT_ARCH" = "i386" ]
   then
      haxe -main HaxeTest -cpp cpp -lib neash -lib nme  --remap neko:cpp --remap flash:neash -D iphonesim
   else
      haxe -main HaxeTest -cpp cpp -lib neash -lib nme  --remap neko:cpp --remap flash:neash -D iphoneos
   fi
</pre>
<p></code><br />
   You can untick the &#8220;Show Environment&#8221; if you do not need to debug this.</p>
<p>   One last step &#8211; drag the &#8220;Compile Haxe&#8221; target into the &#8220;Haxe Test&#8221; target.<br />
   It should now also show up as first item &#8220;under&#8221; the &#8220;Haxe Test&#8221; target.<br />
   The build order should now be correct. (See image at end of post)</p>
<li> Now you are ready to do the build.  The first time you build, the build<br />
     results will show &#8220;Running custom shell script&#8230;&#8221; for quite a while.<br />
    Haxe compiles to cpp very quickly, but it take a while for the cpp files<br />
     to compile to a library.  You can see the progress if you expand out the<br />
     middle tab bit.</p>
<p>   At this stage, you should get a bunch or errors when linking, but also haxe<br />
   should have created a library for you.  Add this library to the project -<br />
   it should be in the local <em>cpp/HaxeTest.iphonesim.a</em>.</p>
<li> Compiling now gets a bunch of unresolved functions from frameworks.<br />
    Add the following frameworks to the project (Add > Existing Frameworks):
<ul>
<li>QuartzCore
<li>OpenGLES
<li>AudioToolbox
     </ul>
<p>These can be found in <em>/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/Library/Frameworks/</em>.</p>
<li><strong> Run!</strong><br />
    So you should be good to go.  Open up the debug console so you can see<br />
     any traces/printfs.</p>
<li> Change the target to &#8220;<strong>Device &#8211; IPhone OS</strong>&#8221; from the pull-down and hit &#8220;Build and Go&#8221;.<br />
   Again, this takes quite a while the first time.<br />
   Now add the new <em>cpp/HaxeTest.iphoneos.a</em> library to the project.</p>
<li>  Now you need to sort out your code signing. If you have not done so already,<br />
      setup you apple developer account &#038; certificates on the apple web site.<br />
      Go to the info of the &#8220;Haxe Test&#8221; executable and the &#8220;properties&#8221; tab.<br />
      Change the &#8220;Identifier&#8221; to match one of your cerificates.  Make sure to<br />
      match your company URL.  You may want to use &#8220;*&#8221; when creating your<br />
      profile for easy changing.  </p>
<p>     Under the &#8220;Build&#8221; tab, under the &#8220;Code Signing&#8221; bit<br />
      in the &#8220;Any iPhone Device&#8221; pull down your profile.  If you don&#8217;t have one then<br />
      you will need to create one on the apple website.</p>
<li>   Connect up your iPhone(iPod touch) and build! W00t!
</ol>
<p><a href="http://gamehaxe.com/wp-content/uploads/2009/07/HaxeTest.png"><img src="http://gamehaxe.com/wp-content/uploads/2009/07/HaxeTest-300x226.png" alt="HaxeTest" title="HaxeTest" width="300" height="226" class="alignleft size-medium wp-image-213" /></a></p>
<p>I have had all sorts of errors when trying to upload to the device.<br />
So far, they have been solved by getting out of the car, walking around it and getting back in.<br />
ie, Disconnect and power down ipod.  Fully exit Xcode and the start it all up and try again.  Also, uninstalling the app from the &#8220;Windows > Orgainiser&#8221; directory can help.<br />
<br />
But now the easy bit.  Change to HaxeTest.hx file, and hit Build &#038; Go.  It is that simple.<br />
Errors should show up nicely in xcode.<br />
<br />
You can add data files (eg, pngs, xml etc) to the project and they will be copied to device so you can open them with a relative path.<br />
<br />
In the properties of the &#8220;Info.plist&#8221; you can set a Icon File &#8211; don&#8217;t forget to add the icon to the project too.<br />
<br />
Not covered here (because I have not fully sorted it out myself):</p>
<ul>
<li> Syntax highlighting in XCode
<li> Debug build (hxcpp can do then &#8211; it&#8217;s a matter of setting up Xcode)
<li> Code completion in Xcode
<li> Automating this procedure!
</ul>
<p><em>Edit: Add framework path, SDL version, MainWindow clearing.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://gamehaxe.com/2009/07/28/haxe-iphone-cpp-at-last/feed/</wfw:commentRss>
		<slash:comments>146</slash:comments>
		</item>
	</channel>
</rss>

