<?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>Christian's Projects &#187; C++</title>
	<atom:link href="http://www.incasoftware.de/~kamm/projects/index.php/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.incasoftware.de/~kamm/projects</link>
	<description></description>
	<lastBuildDate>Thu, 06 May 2010 17:22:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Star Guard level editor</title>
		<link>http://www.incasoftware.de/~kamm/projects/index.php/2010/05/06/star-guard-level-editor/</link>
		<comments>http://www.incasoftware.de/~kamm/projects/index.php/2010/05/06/star-guard-level-editor/#comments</comments>
		<pubDate>Thu, 06 May 2010 17:22:28 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Qml]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://www.incasoftware.de/~kamm/projects/?p=85</guid>
		<description><![CDATA[I spent the last few evenings working on a fun side project which is now complete: a level editor for Loren Schmidt&#8217;s Star Guard.


the first level of Star Guard


the same scene in the editor

A few things came together that caused me to make this level editor:

I was looking for an excuse to do something interesting [...]]]></description>
			<content:encoded><![CDATA[<p>I spent the last few evenings working on a fun side project which is now complete: a level editor for Loren Schmidt&#8217;s <a href="http://vacuumflowers.com/star_guard/star_guard.html">Star Guard</a>.<br />
<span id="more-85"></span></p>
<div style="float: right; margin-left: 40px; margin-bottom: 20px; text-align: center; width: 50%;"><img src="http://www.incasoftware.de/~kamm/starguardleveleditor/sg-level1.png" alt="first level of Star Guard" />
<p>the first level of Star Guard</p>
</div>
<div style="float: right; margin-left: 40px; text-align: center; width: 50%;"><img src="http://www.incasoftware.de/~kamm/starguardleveleditor/sg-level1-editor.png" alt="the same scene in the editor" />
<p>the same scene in the editor</p>
</div>
<p>A few things came together that caused me to make this level editor:</p>
<ul>
<li>I was looking for an excuse to do something interesting with QML.</li>
<li>Star Guard is a great game and stores its levels in friendly, easily accessible XML files.</li>
<li>When I emailed Loren about the project, he allowed me to use some of the game&#8217;s artwork.</li>
</ul>
<p>The whole thing was surprisingly easy to do, took a couple of days and amounted to less than 1200 lines of code &#8211; one half of it QML and the other C++.</p>
<p>If you don&#8217;t know about QML: It&#8217;s a fairly new part of the <a href="http://qt.nokia.com">Qt framework</a>, essentially an extension of JavaScript to build user interfaces declaratively &#8211; and great fun to work with. All the details can be found on <a href="http://doc.qt.nokia.com/4.7-snapshot/declarativeui.html">its documentation page</a> and if you want to get started, the <a href="http://qt.nokia.com/developer/qt-qtcreator-prerelease">Qt 4.7 beta1 packages have just been released</a>.</p>
<p>The editor uses QML to describe every aspect of the user interface. It&#8217;s turned out to be very useful in the beginning of the project when the editor was still QML-only and the interface layout and behavior changed a lot. It also means that it&#8217;d be very easy to redo the user interface now &#8211; even for someone without any C++ knowledge. Also, not having to recompile after every step simply makes fiddling with the UI a lot more pleasant. </p>
<p>Of course there&#8217;s the disadvantage of not following the native look and feel. But no one ever complains that most games don&#8217;t use it &#8211; and I don&#8217;t think it&#8217;s necessary for a level editor to look just like your spreadsheet application either.</p>
<p>The C++ part deals with the backend work, like providing a model that holds the map, a QML item that paints it, and loading from and saving to files. I used the QML plugin mechanism to expose these to the UI code.</p>
<p>The editor is fully functional; I consider it done and will not continue working on it. If someone wants to improve it or base his own tile based level editor on it, feel free! I release the code under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License 1.0</a>.</p>
<p><a href="http://www.incasoftware.de/~kamm/starguardleveleditor/starguard-leveleditor-linux64.tar.bz2">Linux binary (64 bit) and source code (12 MB)</a><br />
<a href="http://www.incasoftware.de/~kamm/starguardleveleditor/starguard-leveleditor-win32.zip">Windows binary and source code (10 MB)</a><br />
<a href="http://www.incasoftware.de/~kamm/starguardleveleditor/starguard-leveleditor-source.tar.bz2">source code only (.tar.bz2, 20 kB)</a><br />
<a href="http://www.incasoftware.de/~kamm/starguardleveleditor/starguard-leveleditor-source.zip">source code only (.zip, 30 kB)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.incasoftware.de/~kamm/projects/index.php/2010/05/06/star-guard-level-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compilers for the D programming language: DMD, GDC and LDC</title>
		<link>http://www.incasoftware.de/~kamm/projects/index.php/2008/07/09/compilers-for-the-d-programming-language/</link>
		<comments>http://www.incasoftware.de/~kamm/projects/index.php/2008/07/09/compilers-for-the-d-programming-language/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 17:12:26 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[LDC]]></category>
		<category><![CDATA[LLVM]]></category>

		<guid isPermaLink="false">http://www.incasoftware.de/~kamm/projects/?p=8</guid>
		<description><![CDATA[Currently, users of the D programming language can essentially choose between two mature compilers: DMD and GDC. I&#8217;ve started helping with the development of a third, LDC, and think the first public alpha version can&#8217;t be far off. In this post, I&#8217;ll give a short overview of the compilers available and say a few words [...]]]></description>
			<content:encoded><![CDATA[<p>Currently, users of the <a href="http://www.digitalmars.com/d/">D programming language</a> can essentially choose between two mature compilers: DMD and GDC. I&#8217;ve started helping with the development of a third, LDC, and think the first public alpha version can&#8217;t be far off. In this post, I&#8217;ll give a short overview of the compilers available and say a few words about LDC.<br />
<span id="more-8"></span><br />
First, there is the reference compiler DMD that is maintained and improved by D&#8217;s inventor Walter Bright. It has a stable branch for D 1.0 as well as a bleeding edge counterpart for version 2.0 of the D specification that&#8217;s still under development. One part of it, the front-end responsible for parsing code, building a syntax tree and running semantics, is open source, available under the GPL or Artistic license. Its back-end, however, is not available and thus only Walter can compile DMD.</p>
<p>This is not a failing in itself. Indeed most users will never have the need or desire to compile their compiler from source. Yet it also prohibits testing patches for the front-end, makes debugging nigh impossible and generally complicates helping with DMD&#8217;s development.</p>
<p>The alternative &#8211; and often the only alternative if your target is not x86 Linux or Windows &#8211; is <a href="http://dgcc.sourceforge.net/">GDC</a>. David Friedman took the open front-end and tied it to the GCC back-end, he even supports D 2.0 to some extend. While it works well and is fully open source, it has, unfortunately, remained a one-man effort. For me it was a combination of GCC&#8217;s daunting code base and the fact that there had been no activity for several months that stopped me from helping out.</p>
<p>Instead I eventually joined a different project: <a href="http://www.dsource.org/projects/ldc/">LDC</a>. It is similar to GDC in that it also takes the open DMD front-end and aims to combine it with an equally free code generator. The back-end, though, is different: as the name suggests LDC emits <a href="http://www.llvm.org/">LLVM</a> bitcode, which can be compiled to native code, but could also be used for Just-in-Time compilation among other things. I&#8217;m also happy to say that even though LLVM is a large and ambitious project, it remains surprisingly easy to learn and work with.</p>
<p>Almost the first thing I did when I started contributing to LDC a few months back, was to integrate Thomas Kühne&#8217;s exhaustive <a href="http://dstress.kuehne.cn/">DStress test suite</a> with LDC: it is very useful for finding bugs and regressions and can even serve as a sort of <a href="http://www.incasoftware.de/~kamm/ldc/tests/index.html">crude progress indicator</a> (crude because there is no relationship between number of bugs and number of tests; there are about 1000 tests for inline assembly and only 30 or so for exception handling). As you can see, there are still a handful (<a href="http://www.incasoftware.de/~kamm/ldc/tests/index.html">517 at the last count</a>) of regressions with respect to DMD, but their number has been decreasing steadily.</p>
<p>In the last months, Tomas Lindquist Olsen, who started the project about a year ago and is responsible for almost all of its existing functionality, and I have added the last major missing parts to the compiler: inline assembly (thanks to David Friedman for the asm parsing and rewriting code!), exception handling and the synchronized statement are now supported. With these out of the way, goals for the future are squashing bugs, fixing some linking issues and getting LDC to work properly on Windows.</p>
<p>Speaking of other platforms: As Tomas and I both develop on x86 Linux, other configurations didn&#8217;t get much testing yet. Some people reported partial successes on <a href="http://dsource.org/forums/viewtopic.php?t=4019&#038;sid=7972120d03053e1f4619d7fef4832030">FreeBSD</a> and <a href="http://dsource.org/forums/viewtopic.php?t=3296&#038;sid=7972120d03053e1f4619d7fef4832030">Sparc</a> but more testers would be welcome. You can generally contact us by email or in #ldc on freenode. All in all, we&#8217;ve made great progress and if we can keep it up, LDC will be in the same league as DMD and GDC soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.incasoftware.de/~kamm/projects/index.php/2008/07/09/compilers-for-the-d-programming-language/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>MATLAB file access</title>
		<link>http://www.incasoftware.de/~kamm/projects/index.php/2007/10/05/matlab-file-access/</link>
		<comments>http://www.incasoftware.de/~kamm/projects/index.php/2007/10/05/matlab-file-access/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 19:51:57 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[MATLAB]]></category>
		<category><![CDATA[scientific computing]]></category>

		<guid isPermaLink="false">http://www.incasoftware.de/~kamm/projects/index.php/2007/10/05/matlab-file-access/</guid>
		<description><![CDATA[Quite a while ago I was looking at ways to interface between MATLAB and a C++ program for a job at university. In the end I wrote a C++ wrapper for the C API to access MAT files which turned out to be quite useful. Since it&#8217;s small and easy to use, I decided to [...]]]></description>
			<content:encoded><![CDATA[<p>Quite a while ago I was looking at ways to interface between <a href="http://www.mathworks.com/products/matlab">MATLAB</a> and a C++ program for a job at university. In the end I wrote a C++ wrapper for the C API to access <a href="http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf">MAT files</a> which turned out to be quite useful. Since it&#8217;s small and easy to use, I decided to release it.<br />
<span id="more-5"></span><br />
At first the plan was to make the program into a MEX file (basically a dynamically linked extension program), but I quickly ran into a problem with <a href="http://www.dealii.org">deal II</a> (an excellent, well documented and object-oriented library for solving partial differential equations with adaptive finite elements): MATLAB altered some of the floating point precision settings which lead to an algorithm in deal II running in an infinite loop (the epsilon value was hardcoded at that time and basically became zero). While the bug was promptly fixed, there were other issues and it was decided that embedding the program was not worth the trouble.</p>
<p>Long story short, I needed a way to read and write the MAT files that MATLAB generates and loads with the &#8216;load&#8217; and &#8217;save&#8217; commands. Using the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/bqoqnz0.html">C API</a> directly seemed cumbersome and error prone, so this C++ wrapper was born.</p>
<p>Download it (4 kB) as <a href="http://www.incasoftware.de/~kamm/projects/wp-content/articles/MATLAB-file-access/matlabfile.tar.bz2">.tar.bz2</a> or as <a href="http://www.incasoftware.de/~kamm/projects/wp-content/articles/MATLAB-file-access/matlabfile.zip">zip</a>.</p>
<p>A basic use case looks like this (also check out test.cc):<br />
<code><br />
#include &quot;matlabfile.h&quot;<br />
using namespace MatlabUtilities;<br />
&nbsp;<br />
File matfile(&quot;some.mat&quot;);<br />
std::vector&lt;double&gt; vec1;<br />
matfile.read&lt;Types::real_vector&gt;(&quot;v1&quot;, vec1);<br />
&nbsp;<br />
double[100] vec2;<br />
matfile.read&lt;Types::fixed_length_real_vector&lt;100&gt; &gt;(&quot;v2&quot;, vec2);<br />
&nbsp;<br />
matfile.write&lt;Types::string&gt;(&quot;hw&quot;, &quot;Hello World!&quot;);<br />
</code></p>
<p>Not all MATLAB types are implemented (check Types namespace in matlabaccessors.h for a list), in particular real matrices with a column and row length different from one are missing for two reasons: I didn&#8217;t need them for the job and you probably have your own preferred matrix type anyway. But don&#8217;t worry, the template-design makes it easy to add these missing features. What needs to be implemented is<br />
<code><br />
struct real_matrix {};<br />
&nbsp;<br />
template &lt;&gt;<br />
struct Reader&lt;real_matrix, MyMatrix&gt; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;static void read(mxArray* var, MyMatrix&amp; result);<br />
}<br />
&nbsp;<br />
template &lt;&gt;<br />
struct Writer&lt;real_matrix, MyMatrix&gt; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;static mxArray* write(MyMatrix&amp; source);<br />
}<br />
&nbsp;<br />
template &lt;&gt;<br />
struct TypeCheck&lt;real_matrix&gt; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;static bool typeCheck(mxArray* var);<br />
}<br />
</code></p>
<p>where the &#8216;read&#8217; function reads data from the mxArray into result, &#8216;write&#8217; returns a new mxArray filled with source&#8217;s data and &#8216;typeCheck&#8217; returns true if the mxArray contains a real_matrix. With these template specializations in place you can use the new code like this:<br />
<code><br />
MyMatrix mat;<br />
matfile.read&lt;real_matrix&gt;(&quot;somevarname&quot;, mat);<br />
matfile.write&lt;real_matrix&gt;(&quot;someother&quot;, mat);<br />
</code><br />
Similarly, you can add a new reader to say &#8216;real_vector&#8217; to accomodate for your own vector type.</p>
<p>The code snippet only contains code for reading and writing data. Other management functionality, like listing all fields in a MAT file is not implemented. I hope it will nevertheless be useful for someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.incasoftware.de/~kamm/projects/index.php/2007/10/05/matlab-file-access/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
