<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Open game programming</title>
	<atom:link href="http://codeflow.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeflow.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 20 Jan 2012 22:20:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='codeflow.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Open game programming</title>
		<link>http://codeflow.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://codeflow.wordpress.com/osd.xml" title="Open game programming" />
	<atom:link rel='hub' href='http://codeflow.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The reasons I don&#8217;t write all my code in Haskell</title>
		<link>http://codeflow.wordpress.com/2011/02/20/the-reasons-i-dont-write-all-my-code-in-haskell/</link>
		<comments>http://codeflow.wordpress.com/2011/02/20/the-reasons-i-dont-write-all-my-code-in-haskell/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 11:55:37 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[cabal]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[ghc]]></category>
		<category><![CDATA[portability]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=135</guid>
		<description><![CDATA[Those of you who&#8217;ve been checking out my projects might have noticed that I wrote my latest one in C++. The two previous projects I had written in Haskell. So why the switch? I&#8217;ll write down a small summary of the pros and cons of the both languages that influenced my decision. I&#8217;ll start with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=135&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Those of you who&#8217;ve been checking out my projects might have noticed that I wrote my latest one in C++. The two previous projects I had written in Haskell. So why the switch? I&#8217;ll write down a small summary of the pros and cons of the both languages that influenced my decision.</p>
<p>I&#8217;ll start with the things that spoke for Haskell.</p>
<ul>
<li>Haskell, in general, allows a lot more abstract, safer, higher level way of programming. Of course, you already knew this, but it&#8217;s still worth mentioning.</li>
<li>Hackage has tons of useful packages which makes using libraries and all the associated bureaucracy really simple. (Hackage is basically a repository consisting of almost all open sourced Haskell programs and libraries.) Combine this with cabal, which downloads, compiles and installs the dependencies for you automatically.</li>
<li>C++ compile times, especially with Boost, are abysmal.</li>
</ul>
<p>And now for the cons, or, put in a more positive light, pros for C++.</p>
<ul>
<li>It&#8217;s much easier to reason about performance in C++ than in Haskell. This is given, I guess, and the simple solution is to become a Haskell champion who can spot a space leak a mile away, but it bothers me nevertheless. There was a <a href="http://comments.gmane.org/gmane.comp.lang.haskell.cafe/85976">nice post and thread</a> at Haskell cafe a while back about this.</li>
<li>Writing portable code in Haskell is not as easy as with C++. With portable I mean 1) code that runs on x86 across operating systems  (Windows, Linux and Mac), and 2) code that runs across architectures  (x86, ARM, MIPS, etc.). While portability is not as trendy anymore as it once was, I still have the twisted opinion that high quality code in a higher level language absolutely must be portable, otherwise it&#8217;s not high quality, and the Haskell ecosystem currently has limited support for writing portable code. Portable across operating systems is relatively simple with Haskell using GHC (although there are <a href="http://jpmoresmau.blogspot.com/2010/05/haskell-sdl-on-windows-check-hacking.html">exceptions</a>), but portable across architectures is a pain. GHC, the defacto standard Haskell compiler, <a href="http://hackage.haskell.org/trac/ghc/wiki/Platforms">actively supports only x86</a> and doesn&#8217;t <a href="http://hackage.haskell.org/trac/ghc/wiki/CrossCompilation">cross compile</a>. Some of the other Haskell compilers do compile across architectures, but they don&#8217;t support all the GHC extensions (which are used by a lot of Hackage packages) and often have a huge performance gap with GHC, which leaves me with zero Haskell compilers I&#8217;m 100% happy with. Don&#8217;t get me wrong, I still appreciate GHC and think it&#8217;s magical, but there&#8217;s room for improvement.</li>
<li>The Haskell libraries are in a constant flux. I&#8217;ve been writing Haskell code for a couple of years now, and each time a new GHC version came out, the old code broke. Usually the libraries included with GHC are updated and the interface was changed. Or GHC behaves a bit differently regarding some minor points and the code breaks. Or cabal, which has its main releases together with GHC, has some new features and the code breaks. There are plans for fixing the libraries once and for all (I can&#8217;t find the link now), which I think is a great idea, but when they do (and until they do), there&#8217;ll be breakage again.</li>
<li>Cabal, while great in general, has its problems, namely what cdsmith felicitously dubbed <a href="http://cdsmith.wordpress.com/2011/01/16/haskells-own-dll-hell/">Haskell&#8217;s own DLL hell</a>.</li>
</ul>
<p>As can be seen from the list, the negative issues I see concerning Haskell are mostly not about the language itself but the infrastructure. That makes sense, I guess; Haskell, although it has a great community, is a less used language, especially in the industry, which makes it more difficult to establish an infrastructure that can compete with the one of, say, C++. The problems I have with C++, on the other hand, concern the language itself, which, although useful, is not really what one might consider the crown jewel of language design.</p>
<p>The infrastructure is at least something that can be fixed.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/135/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=135&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2011/02/20/the-reasons-i-dont-write-all-my-code-in-haskell/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>
	</item>
		<item>
		<title>Hooray! A new open source Civilization-like game!</title>
		<link>http://codeflow.wordpress.com/2011/02/06/hooray-a-new-open-source-civilization-like-game/</link>
		<comments>http://codeflow.wordpress.com/2011/02/06/hooray-a-new-open-source-civilization-like-game/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 17:53:42 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[game]]></category>
		<category><![CDATA[civilization]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=122</guid>
		<description><![CDATA[Behold, Kingdoms 0.1.0 has been released. Kingdoms is a hobby project of mine I&#8217;ve been working on for the past couple of months. It&#8217;s a strategy game, where you lead a nation from stone age until the bittersweet end &#8211; in other words, a Civilization-like game. I&#8217;ve been wanting to write one for a long [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=122&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Behold, Kingdoms 0.1.0 has been released. Kingdoms is a hobby project of mine I&#8217;ve been working on for the past couple of months. It&#8217;s a strategy game, where you lead a nation from stone age until the bittersweet end &#8211; in other words, a Civilization-like game. I&#8217;ve been wanting to write one for a long time, and I&#8217;m glad to see it&#8217;s doable.﻿</p>
<p>It borrows features from all Civilization games I&#8217;ve played: graphics from Civ 1 (because I&#8217;m no artist), the configuration file type from Civ 2 (back when it was simple), strategic resources and culture from Civ 3 and (part of) the combat system from Civ 4. By the way, that&#8217;s also the reason why I wanted something else than FreeCiv: I find it&#8217;s too similar to Civ 2, which was never my favorite Civ game.</p>
<p>Here are some screenshots:</p>
<div id="attachment_123" class="wp-caption alignnone" style="width: 460px"><a href="http://codeflow.files.wordpress.com/2011/02/normal-2-thumb.png"><img class="size-full wp-image-123" title="normal-2-thumb" src="http://codeflow.files.wordpress.com/2011/02/normal-2-thumb.png?w=450&#038;h=337" alt="" width="450" height="337" /></a><p class="wp-caption-text">Babylonians vs. Aztecs</p></div>
<div id="attachment_124" class="wp-caption alignnone" style="width: 460px"><a href="http://codeflow.files.wordpress.com/2011/02/egyptians-complete-thumb.png"><img class="size-full wp-image-124" title="egyptians" src="http://codeflow.files.wordpress.com/2011/02/egyptians-complete-thumb.png?w=450&#038;h=337" alt="" width="450" height="337" /></a><p class="wp-caption-text">A map editor is included</p></div>
<p>You can get Kingdoms from <a href="http://anttisalonen.github.com/kingdoms/">its web page</a> &#8211; there&#8217;s the <a href="https://github.com/anttisalonen/kingdoms">source</a> as well as the <a href="http://anttisalonen.github.com/kingdoms/kingdoms-0.1.0.zip">Windows binary</a>. There are still quite a few features I wanted to implement but haven&#8217;t had the time yet, so if something bugs you, let me know.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=122&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2011/02/06/hooray-a-new-open-source-civilization-like-game/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>

		<media:content url="http://codeflow.files.wordpress.com/2011/02/normal-2-thumb.png" medium="image">
			<media:title type="html">normal-2-thumb</media:title>
		</media:content>

		<media:content url="http://codeflow.files.wordpress.com/2011/02/egyptians-complete-thumb.png" medium="image">
			<media:title type="html">egyptians</media:title>
		</media:content>
	</item>
		<item>
		<title>Wrapping C++ libraries for Haskell</title>
		<link>http://codeflow.wordpress.com/2011/01/03/wrapping-c-libraries-for-haskell/</link>
		<comments>http://codeflow.wordpress.com/2011/01/03/wrapping-c-libraries-for-haskell/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 15:40:26 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[ffi]]></category>
		<category><![CDATA[ogre]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=87</guid>
		<description><![CDATA[I noticed I still haven&#8217;t blogged about a project I worked on some time ago, so here goes. A long time ago I wrote a small library for wrapping OGRE in Haskell. I wrote it manually, i.e. first writing some C functions that call C++ and have a C interface, and then wrote some Haskell [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=87&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I noticed I still haven&#8217;t blogged about a project I worked on some time ago, so here goes.</p>
<p>A long time ago I wrote a small library for wrapping <a href="http://www.ogre3d.org/">OGRE</a> in <a href="http://www.haskell.org/">Haskell</a>. I wrote it manually, i.e. first writing some C functions that call C++ and have a C interface, and then wrote some Haskell functions to call the C functions. That&#8217;s the principle when wrapping C++ libraries in most higher level languages, mainly because most language implementations support calling C, but not C++.</p>
<p>Now, by writing the whole wrapper manually you have the complete power of the resulting interface, so you can try to bend the C interface so that the resulting interface has the natural feel of the higher level language you&#8217;re writing the binding for. The negative side to this is, of course, that it&#8217;s lots of work, and more or less tedious at that. There are therefore a lot of programs that automate some or part of the process of writing bindings to C libraries. So when wrapping a C library for Haskell, you can use a tool like <a href="http://hackage.haskell.org/package/hsc2hs">hsc2hs</a>, <a href="http://hackage.haskell.org/package/bindings-DSL">bindings-DSL</a> or <a href="http://hackage.haskell.org/package/c2hs">c2hs</a>.</p>
<p>But it gets more problematic when you want to wrap C++ code. In the end you somehow have to wrap the C++ code to C &#8211; either manually or automatically. Some C++ libraries maintain their own C wrappers, like <a href="http://bulletphysics.org/">bullet</a> and <a href="http://llvm.org/">LLVM</a>. For others, the wrapper writers must either write or generate their own C wrappers. When it comes to Haskell bindings for C++ libraries, the C wrappers were written manually at least for <a href="http://hackage.haskell.org/package/IrrHaskell">Irrlicht</a>. I also wrote the C wrapper manually for the first versions of Hogre. As for the libraries that generate the C wrapper using a tool, there&#8217;s at least <a href="http://qthaskell.berlios.de/">qtHaskell</a>.</p>
<p>Now, at some point it got tiresome to manually write the Haskell bindings to Hogre, so I wrote a tool to automate it. Actually, there are two tools: cgen is a program that parses C++ header files and creates a C wrapper around the C++ library, and cgen-hs is a tool that parses the generated C header files and creates a Haskell wrapper around the C library. Using these two tools I created the newest version of Hogre, which is a lot more complete than the previous, manually written binding.</p>
<p>I also wrote a small example on how cgen works that I&#8217;ll demonstrate here. The input is Animals, a C++ library that allows access to a programmatic use of a wide range of animals. It&#8217;s a header-only library because I wanted to keep it simple, but that doesn&#8217;t really make a difference here. It&#8217;s split across three header files, listed here:</p>
<p><pre class="brush: cpp;">
namespace Animals {
class Animal {
    public:
        Animal() : age(0) { }
        ~Animal() { }
        virtual void make_sound() = 0;
        int get_age() const
        {
            return age;
        }
        void increment_age()
        {
           age++;
        }
    private:
        int age;
};
class Dog : public Animal {
    public:
        Dog() { }
        void make_sound()
        {
            std::cout &lt;&lt; &quot;Growl!\n&quot;;
        }
};

class Sheep : public Animal {
    public:
        Sheep(int wooliness_level_ = 0)
            : wooliness_level(wooliness_level_)
        { }
        void make_sound()
        {
             std::cout &lt;&lt; &quot;Baa!\n&quot;;
        }
        void shear()
        { /* something */ }
    private:
        int wooliness_level;
};
}
</pre></p>
<p>So, given this piece of code one can feed it to cgen, which generates a C interface for it. The result looks something like this (simplified):</p>
<p><pre class="brush: cpp;">
/* Sheep.h */
void Animals_Sheep_delete(Sheep* this_ptr);
Sheep* Animals_Sheep_new(int wooliness_level_);
void Animals_Sheep_make_sound(Sheep* this_ptr);
void Animals_Sheep_shear(Sheep* this_ptr);
/* Sheep.cpp */
void Animals_Sheep_delete(Sheep* this_ptr)
{
    delete this_ptr;
}

Sheep* Animals_Sheep_new(int wooliness_level_)
{
    return new Sheep(wooliness_level_);
}

void Animals_Sheep_make_sound(Sheep* this_ptr)
{
    this_ptr-&gt;make_sound();
}

void Animals_Sheep_shear(Sheep* this_ptr)
{
    this_ptr-&gt;shear();
}
</pre></p>
<p>So there we have a C wrapper for a C++ library ready for compilation.</p>
<p>For writing the Haskell binding, the next step is to run the next tool, cgen-hs. It takes the generated headers of the C wrapper as input, and as output creates a Haskell library that wraps the C library. The output looks something like this:</p>
<p><pre class="brush: plain;">
{-# LANGUAGE ForeignFunctionInterface #-}
module Sheep(
sheep_with, 
sheep_delete, 
sheep_new, 
sheep_make_sound, 
sheep_shear
)

where

import Types
import Control.Monad

import Foreign
import Foreign.C.String
import Foreign.C.Types

sheep_with :: Int -&gt; (Sheep -&gt; IO a) -&gt; IO a
sheep_with p1 f = do
    obj &lt;- sheep_new p1
    res &lt;- f obj
    sheep_delete obj
    return res

foreign import ccall &quot;Sheep.h Animals_Sheep_delete&quot; c_sheep_delete :: Sheep -&gt; IO ()
sheep_delete :: Sheep -&gt; IO ()
sheep_delete p1 =   c_sheep_delete p1

foreign import ccall &quot;Sheep.h Animals_Sheep_new&quot; c_sheep_new :: CInt -&gt; IO Sheep
sheep_new :: Int -&gt; IO Sheep
sheep_new p1 =   c_sheep_new (fromIntegral p1)

foreign import ccall &quot;Sheep.h Animals_Sheep_make_sound&quot; c_sheep_make_sound :: Sheep -&gt; IO ()
sheep_make_sound :: Sheep -&gt; IO ()
sheep_make_sound p1 =   c_sheep_make_sound p1

foreign import ccall &quot;Sheep.h Animals_Sheep_shear&quot; c_sheep_shear :: Sheep -&gt; IO ()
sheep_shear :: Sheep -&gt; IO ()
sheep_shear p1 =   c_sheep_shear p1
</pre></p>
<p>Then one can write a Haskell program using this new Haskell library, and run it for the output:</p>
<p><pre class="brush: plain;">
$ cat Main.hs
module Main
where

import Control.Monad (replicateM_)

import Types
import Animal
import Dog
import Sheep

main = do
  dog_with $ \d -&gt; 
    sheep_with 1 $ \s -&gt; do
      dog_make_sound d
      sheep_make_sound s
      sheep_shear s
      replicateM_ 5 $ animal_increment_age (toAnimal s)
      animal_get_age (toAnimal s) &gt;&gt;= \a -&gt; putStrLn $ &quot;The sheep is now &quot; ++ show a ++ &quot; years old!&quot;
$ ./Main
Growl!
Baa!
The sheep is now 5 years old!
</pre></p>
<p>So, everything seems to work well, and the newest Hogre version can be found at <a href="http://hackage.haskell.org/package/hogre">Hackage</a>, as well as <a href="http://hackage.haskell.org/package/cgen">cgen</a>.</p>
<p>Cgen is, however, in a very early stage of development and has, therefore, some weaknesses. First of all, it&#8217;s not a complete C++ parser, not even close, so it fails to parse many C++ header files. After configuring it for OGRE, it does manage to parse about two thirds of the OGRE headers, which is a good start, I guess. The C++ parser was the first real parser I wrote using Parsec, so a rewrite is probably the way to go.</p>
<p>Second of all, as I&#8217;ve only seriously used cgen for OGRE, it makes some assumptions about the C++ headers that may not hold for other libraries. The most critical one is probably that cgen-hs expects that all the classes and functions to wrap are in some namespace, which leads to problems when wrapping libraries that reside in the global namespace.</p>
<p>The third weakness is that it the generated Haskell functions are simply all in the IO monad, which suits well for OGRE (which doesn&#8217;t really have that many pure functions), but may be far from ideal for another library. Finally, cgen currently doesn&#8217;t support any class templates, neither wrapping them or using them as parameters or return values, so wrapping interfaces that rely heavily e.g. on STL will be troublesome. For Hogre this is not really a killer, although it does prevent the Hogre user from using some features that are available in OGRE.</p>
<p>All in all, however, cgen is working well for Hogre, and if you&#8217;re planning on writing a binding for a C++ library, you can give it a try. For more information, see the <a href="http://anttisalonen.github.com/cgen/">cgen homepage</a>, <a href="http://anttisalonen.github.com/cgen/animals.html">a simple example</a>, and the <a href="http://anttisalonen.github.com/hogre/">Hogre homepage</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=87&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2011/01/03/wrapping-c-libraries-for-haskell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>
	</item>
		<item>
		<title>Announcing freekick2</title>
		<link>http://codeflow.wordpress.com/2010/05/04/announcing-freekick2/</link>
		<comments>http://codeflow.wordpress.com/2010/05/04/announcing-freekick2/#comments</comments>
		<pubDate>Tue, 04 May 2010 15:34:57 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[game ai]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sensible soccer]]></category>
		<category><![CDATA[soccer game]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=67</guid>
		<description><![CDATA[About a month ago I announced my then-latest programming project, Star Rover 2. It&#8217;s a space flying game written in Haskell, and while programming that was fun and I learnt a lot from the project, it was time to find something else to do. So I started another soccer project, again in Haskell (like in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=67&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>About a month ago I announced my then-latest programming project, Star Rover 2. It&#8217;s a space flying game written in Haskell, and while programming that was fun and I learnt a lot from the project, it was time to find something else to do. So I started another soccer project, again in Haskell (like in <a href="http://codeflow.wordpress.com/2008/09/19/a-few-more-words-on-freekick/">September 2008</a>), but with a bit more Haskell experience under my belt.</p>
<p>And now, after almost a month, it&#8217;s time for the first release. The new soccer game is called freekick2, and it&#8217;s an open source 2D arcade style soccer game.</p>
<p><a href="http://codeflow.files.wordpress.com/2010/05/fk2-6.png"><img class="alignnone size-full wp-image-69" title="fk2-6" src="http://codeflow.files.wordpress.com/2010/05/fk2-6.png?w=450&#038;h=337" alt="" width="450" height="337" /></a></p>
<p>If you have <a href="http://hackage.haskell.org/platform/">cabal</a>, you can install it with a simple <strong>cabal update &amp;&amp; cabal install freekick2</strong>. Here&#8217;s a screen  shot from a menu:</p>
<p><a href="http://codeflow.files.wordpress.com/2010/05/fk2-10.png"><img class="alignnone size-full wp-image-73" title="fk2-10" src="http://codeflow.files.wordpress.com/2010/05/fk2-10.png?w=450&#038;h=337" alt="" width="450" height="337" /></a></p>
<p>The freekick2 distribution includes only a few fantasy teams, but you can use the data files from a <a href="http://en.wikipedia.org/wiki/Sensible_Soccer_%28series%29">Sensible Soccer </a>game for some additional realism.</p>
<p>One lesson I learnt when doing Star Rover 2 is that I should avoid over-engineering like plague, as that was probably one reason why I couldn&#8217;t get the first Freekick versions in a releaseable state.</p>
<p>Freekick2 now consists of about 3200 lines of Haskell code, around 1000 more than Star Rover 2, and it&#8217;s also a bit fancier, graphics-wise. With Star Rover 2 I used monad transformers to handle the main loop and state changes, which worked pretty well, and I&#8217;m using the same technique with freekick2. I still haven&#8217;t figured out the whole <a href="http://www.haskell.org/haskellwiki/Functional_Reactive_Programming">FRP</a> thing, but game programming in Haskell seems to work out pretty well without.</p>
<p>Things I&#8217;ve learnt while programming freekick2:</p>
<p>* Texture mapping with OpenGL in Haskell. To load the textures you need to play around with pointers a bit, which are not really that usual in Haskell. But you can do it, and with the help of some great small libraries like <a href="http://hackage.haskell.org/package/pngload">pngload</a> it&#8217;s relatively simple in the end. Adding dynamic recoloring of the textures after loading them (to support multiple kit colors) was fun as well.</p>
<p>* Parsing binary data in Haskell. Over a year ago, <a href="http://codeflow.wordpress.com/2009/01/10/freekick-the-c-way/">when I was writing Freekick in C++</a>, I wanted to deserialize the SWOS data files (<a href="http://yodasoccer.sourceforge.net/fformat.htm">the format&#8217;s known</a>; many thanks to the ones who figured the format out) and I thought parsing binary data sounds like a job for C or C++. <a href="http://github.com/anttisalonen/freekick/blob/master/src/tools/swos2fk/main.cpp">The result from back then</a> is about 850 lines long and took a few hours to write. Granted, it also generates some XML. Now I wrote a program to do the same task in Haskell; the <a href="http://github.com/anttisalonen/freekick2/blob/master/src/Swos.hs">result</a> has 250 lines and was written in less than two hours. The Haskell version also includes code for writing SWOS data files &#8211; a feature I added just because it was so easy to do. Later, for the freekick-internal data structures, I let <a href="http://darcs.haskell.org/packages/binary/tools/derive/BinaryDerive.hs">BinaryDerive</a> derive the serialization/deserialization code for me. Needless to say, I won&#8217;t be doing binary data parsing in C anymore if I get to choose.</p>
<p>* Template Haskell. The state in freekick2 changes pretty often, and is managed in a State monad. I needed a lot of functions of type (FieldType -&gt; FieldType) -&gt; State -&gt; State (like already with Star Rover 2), usually one for each field in a record, and so I let TH generate them all for me. Bulat&#8217;s tutorials (links to them can be found <a href="http://www.haskell.org/haskellwiki/Template_Haskell">here</a>) were a life saver.</p>
<p>* Implementing a GUI with colors, textures and dynamic content, with a tree-like hierarchy for screens.</p>
<p>* Use of the <a href="http://hackage.haskell.org/trac/haskell-prime/wiki/ExistentialQuantification">existential quantification</a> language extension for <a href="http://www.haskell.org/haskellwiki/Heterogenous_collections">heterogeneous collections</a>. I&#8217;ve spent some time with object oriented design in the past, which sometimes leads to object-oriented designs in Haskell, so that something like existential types are needed. In this concrete case, I created the class Sprite, with both the player and the ball implementing it. The easiest way to draw all sprites sorted by depth is then to just put all sprites in one list and sort it. Without existential quantification, I would&#8217;ve had to write code to sort the players and then call the draw method of the ball somewhere between the draw methods of the players.</p>
<p>So, programming in Haskell is more fun than ever, and the productivity boost given by Haskell is starting to show more and more.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=67&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2010/05/04/announcing-freekick2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>

		<media:content url="http://codeflow.files.wordpress.com/2010/05/fk2-6.png" medium="image">
			<media:title type="html">fk2-6</media:title>
		</media:content>

		<media:content url="http://codeflow.files.wordpress.com/2010/05/fk2-10.png" medium="image">
			<media:title type="html">fk2-10</media:title>
		</media:content>
	</item>
		<item>
		<title>Announcing Star Rover 2</title>
		<link>http://codeflow.wordpress.com/2010/04/05/55/</link>
		<comments>http://codeflow.wordpress.com/2010/04/05/55/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 13:39:57 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[game]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[sdl]]></category>
		<category><![CDATA[software design]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=55</guid>
		<description><![CDATA[Here&#8217;s the announcement of my latest programming project. It&#8217;s called Star Rover 2, and it&#8217;s a space flying game. You can fly around in space, trade goods, fight against other ships and complete missions for different governments. It features different difficulty levels, a high score list and several ways for the player to play the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=55&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the announcement of my latest programming project. It&#8217;s called Star Rover 2, and it&#8217;s a space flying game. You can fly around in space, trade goods, fight against other ships and complete missions for different governments. It features different difficulty levels, a high score list and several ways for the player to play the game. It&#8217;s also the first game I wrote in Haskell that&#8217;s actually playable.</p>
<p><a href="http://codeflow.files.wordpress.com/2010/04/sr2-4.png"><img class="alignnone size-medium wp-image-56" title="sr2" src="http://codeflow.files.wordpress.com/2010/04/sr2-4.png?w=300&#038;h=225" alt="Flying between planets" width="300" height="225" /></a></p>
<p>The game itself is quite simple: you start on a planet, and you can buy some cargo if you want before launching into the space. In space, you can fly to other planets and see if you can sell your cargo for a better price. There are other ships in space as well, and you&#8217;ll get interrupted every once in a while when coming across one, with the possibility of attacking the other ship. If you win, you get their cargo, and the various governments may have their opinions about the attack as well.</p>
<div id="attachment_57" class="wp-caption alignnone" style="width: 310px"><a href="http://codeflow.files.wordpress.com/2010/04/sr2-2.png"><img class="size-medium wp-image-57" title="starrover2-combat" src="http://codeflow.files.wordpress.com/2010/04/sr2-2.png?w=300&#038;h=225" alt="(it looks better in motion :)" width="300" height="225" /></a><p class="wp-caption-text">Combat in Star Rover 2</p></div>
<p>As the game progresses, you may earn a reputation among the governing bodies, which leads to new dangers and possibilities. The international relationships are complicated, and attacking a ship of one nationality may not only affect the nationality being attacked but their friends and enemies as well. By playing your cards right you can receive missions from governors, and by completing them you may boost your ranking further.</p>
<div id="attachment_59" class="wp-caption alignnone" style="width: 310px"><a href="http://codeflow.files.wordpress.com/2010/04/sr2-3.png"><img class="size-medium wp-image-59" title="sr2-3" src="http://codeflow.files.wordpress.com/2010/04/sr2-3.png?w=300&#038;h=225" alt="" width="300" height="225" /></a><p class="wp-caption-text">Captured cargo</p></div>
<p>The game is quite non-linear; it ends when your ship is destroyed often enough and you are too weak to continue, or when you choose to retire. At the end, your achievements are rated and you may make it to the high score list. Until then, you may choose your activities freely.</p>
<p>You can find Star Rover 2 at <a href="http://hackage.haskell.org/package/starrover2">Hackage</a>, so if you have <a href="http://www.haskell.org/cabal/">cabal</a>, you can install it by running cabal update &amp;&amp; cabal install starrover2. You can also fetch the sources from <a href="http://github.com/anttisalonen/starrover2">github</a>. As for dependencies, you&#8217;ll need SDL, OpenGL and FTGL.</p>
<p>In the beginning, Star Rover 2 was more or less a test of whether I can actually concentrate on one project enough to have a playable game in the end, and I&#8217;m glad it&#8217;s now reached a state where it can be released. Other than that, I was curious to see what programming such a game actually is like in Haskell, and I&#8217;m quite pleased with the results. I started working on Star Rover 2 on my spare time pretty much exactly a month ago, and now it amounts to about 2000 lines of Haskell code. I was a bit worried I couldn&#8217;t write a larger project in Haskell, but now I can see how well Haskell scales up to complex tasks. This was also my first project where monad transformers actually came in  very handy.</p>
<p>Any feedback and bug reports are of course very welcome.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=55&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2010/04/05/55/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>

		<media:content url="http://codeflow.files.wordpress.com/2010/04/sr2-4.png?w=300" medium="image">
			<media:title type="html">sr2</media:title>
		</media:content>

		<media:content url="http://codeflow.files.wordpress.com/2010/04/sr2-2.png?w=300" medium="image">
			<media:title type="html">starrover2-combat</media:title>
		</media:content>

		<media:content url="http://codeflow.files.wordpress.com/2010/04/sr2-3.png?w=300" medium="image">
			<media:title type="html">sr2-3</media:title>
		</media:content>
	</item>
		<item>
		<title>Programming 3D with Haskell</title>
		<link>http://codeflow.wordpress.com/2009/12/31/programming-3d-with-haskell/</link>
		<comments>http://codeflow.wordpress.com/2009/12/31/programming-3d-with-haskell/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 10:44:48 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[3d programming]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[irrlicht]]></category>
		<category><![CDATA[ogre]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=50</guid>
		<description><![CDATA[If you&#8217;re planning on writing 3D software in Haskell, here are some tips. A few months ago I was planning on programming a 3D game in Haskell and was browsing the options for a 3D library. In general, there are a couple of low-level APIs (OpenGL and Direct3D) and a few higher-level libraries built on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=50&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re planning on writing 3D software in Haskell, here are some tips.</p>
<p>A few months ago I was planning on programming a 3D game in <a href="http://www.haskell.org/">Haskell</a> and was browsing the options for a 3D library. In general, there are a couple of low-level APIs (<a href="http://www.opengl.org/">OpenGL</a> and Direct3D) and a few higher-level libraries built on top of those low-level APIs (<a href="http://www.ogre3d.org/">OGRE</a>, <a href="http://irrlicht.sourceforge.net/">Irrlicht</a>, <a href="http://en.wikipedia.org/wiki/List_of_3D_graphics_APIs">and more</a>).  Using a low-level API has the known advantages (fine-grained control) and disadvantages (lots of code to write).</p>
<p>It turned out that limiting the programming language to Haskell is quite restrictive; almost all higher-level libraries are intended for using with C++ (<a href="http://www.panda3d.org/">Panda3D</a> being an exception with Python as the intended language; the library itself is written in C++, though). So what you need is Haskell bindings for the libraries. There&#8217;s a Haskell binding for <a href="http://hackage.haskell.org/package/OpenGL">OpenGL</a>, which is used for (apparently) all 3D <a href="http://hackage.haskell.org/packages/archive/pkg-list.html#cat:game">games written in Haskell</a>. A few months ago it was the only option and, if you&#8217;re doing anything more complicated than rendering a few models in a scene, it still is.</p>
<p>The problem is that binding a C++ library is rather complicated and basically boils down to either writing C code to wrap the C++ interface and then interfacing the C code in Haskell using FFI or automatically generating the C interface (as well as the Haskell FFI code that wraps it). The latter option was chosen for at least the GUI widget libraries <a href="http://hackage.haskell.org/package/wx">wxHaskell</a> and <a href="http://qthaskell.berlios.de/">qtHaskell</a>.</p>
<p>However, a few Haskell bindings for 3D libraries have appeared. There&#8217;s a very primitive binding to <a href="http://hackage.haskell.org/package/hogre">OGRE</a> written by the author of this post (with <a href="http://hackage.haskell.org/package/hogre-examples">examples</a>) as well as at least a start of a binding to <a href="http://www.althainz.de/haskell-irrlicht-interface.html">Irrlicht</a> by Peter Althainz.  So there appears to be a bit of activity regarding the use of higher-level 3D libraries in Haskell, which is good news, I guess.</p>
<p>One more note regarding the Haskell bindings for Ogre: you can do some simple things like adding models and a camera, and moving them around, but that&#8217;s about it, since I haven&#8217;t really had the motivation or need to provide support for anything else. The bindings are relatively simple to extend, though, so if you use the bindings and miss a feature, go ahead and let me know.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=50&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2009/12/31/programming-3d-with-haskell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>
	</item>
		<item>
		<title>Software development gems</title>
		<link>http://codeflow.wordpress.com/2009/07/14/software-development-gems/</link>
		<comments>http://codeflow.wordpress.com/2009/07/14/software-development-gems/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 22:12:17 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software design]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=46</guid>
		<description><![CDATA[In this blog post, I list some gem-like web pages that are worth reading if you want to become a better software developer. They&#8217;re not simply some sites where you can read about the hype of the week, instead they include insightful material that actually makes you see software development from a whole different perspective. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=46&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this blog post, I list some gem-like web pages that are worth reading if you want to become a better software developer. They&#8217;re not simply some sites where you can read about the hype of the week, instead they include insightful material that actually makes you see software development from a whole different perspective.</p>
<p>The need for mentioning the following sites arises from the fact that most web sites and blogs I find in the net usually make me think the writer either tells me some basics about programming I learned years ago or tries to convince me to use some new, brilliant technology which usually involves XML and/or Java. I often get the feeling I&#8217;m not part of the target audience and look for things that do a better job on motivating me. As it is quite difficult to find such sites, I&#8217;ll spend the few minutes to list some of the sites I&#8217;ve found interesting.</p>
<p>Some time ago I stumbled upon a web site called <a href="http://www.joelonsoftware.com/">Joel on Software</a>. It&#8217;s basically a blog by an experienced software developer, with interesting stories about our industry for us all to read about. It was actually the first software related web page I had found in a long time that managed to inspire me. My favorite article is &#8220;<a href="http://www.joelonsoftware.com/items/2006/08/01.html">Can your programming language do this?</a>&#8220;. As another example, if you&#8217;ve ever wondered about the Hungarian notation &#8211; or cursed at the coding guidelines that force you to use it, even if you can&#8217;t see the usefulness behind it, go read <a href="http://www.joelonsoftware.com/articles/Wrong.html">what Joel has to say</a> about its history and things may become more clear, although not necessarily less frustrating.</p>
<p>I was glad to find such a page and was hoping to find more. Later I stumbled upon the page of <a href="http://www.paulgraham.com/">Paul Graham</a>. He shares some similarities with Joel &#8211; they both have founded a start-up company and written a lot of nice texts about software development. As a programming language enthusiast, I especially find the essays by Paul Graham <a href="http://www.paulgraham.com/avg.html">involving Lisp</a> interesting.</p>
<p>Some days ago I was looking for a new book on software development to buy and came across <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1247607051&amp;sr=8-1">Clean Code by Robert Martin</a>. I haven&#8217;t bought the book &#8211; yet &#8211; but searched for some related material and stumbled upon a presentation by Robert Martin titled <a href="http://railsconf.blip.tv/file/2089545/">&#8220;What Killed Smalltalk Could Kill Ruby, Too&#8221;</a> as well as a <a href="http://enfranchisedmind.com/blog/posts/what-killed-lisp-could-kill-haskell-as-well/">blog post</a> drawing parallels between the aforementioned languages and functional languages, namely Lisp and Haskell. The presentation seems very insightful and makes me not only want to learn more about the history of programming languages but also get a copy of the book.</p>
<p>Gaining interest on the new, modern software development techniques I read about <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> and <a href="http://en.wikipedia.org/wiki/Behaviour-driven_development">BDD</a>. And when you read about acronyms as these you can&#8217;t help coming across the webpage of <a href="http://martinfowler.com/">Martin Fowler</a> sooner or later. Here I also found an <a href="http://www.martinfowler.com/articles/languageWorkbench.html">interesting text</a> about <a href="http://en.wikipedia.org/wiki/Domain_specific_language">DSLs</a>, which I feel is an increasingly important &#8211; and interesting &#8211; topic.</p>
<p>Sites like these help me learn about the new developments in our industry and also make me a better, more efficient developer while still preserving the fun factor. Keep it up!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/46/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=46&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2009/07/14/software-development-gems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>
	</item>
		<item>
		<title>Modularity in software</title>
		<link>http://codeflow.wordpress.com/2009/03/12/40/</link>
		<comments>http://codeflow.wordpress.com/2009/03/12/40/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 18:55:50 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[software design]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[forth]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[interprocess communication]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=40</guid>
		<description><![CDATA[I wanted to start typing down some things as notes I&#8217;ve learnt during the development of Freekick until now before I forget all about them. The first article in the series is about one of the most important things that are different between Freekick and my previous hobby projects: modularization in software. I first started [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=40&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to start typing down some things as notes I&#8217;ve learnt during the development of Freekick until now before I forget all about them. The first article in the series is about one of the most important things that are different between Freekick and my previous hobby projects: modularization in software.</p>
<p>I first started to understand the importance and the benefits of modularity as I read the great book <a href="http://www.faqs.org/docs/artu/">&#8220;The Art of Unix Programming&#8221;</a> by Eric S. Raymond, a book I can recommend to every software developer, even those who&#8217;ve never used or programmed on Unix. Lacking modularity in my programs was the biggest reason why I had to abandon them sooner or later &#8211; I&#8217;ve ended up in such horrible situations where tweaking the AI creates a bug in the main menu, for example.</p>
<p>As mentioned in the book, managing complexity is one of the most crucial (and difficult) jobs when developing software. Basically, as long as you can simplify the tasks of the software into more and more smaller, simpler sub-tasks, and organize them so that you always know which parts of the software should be talking to each other and how the talking is done (interface design), you have no problem. If you lose the overview half-way to the project but go on writing code, you probably won&#8217;t get it finished.</p>
<p>From a developer&#8217;s point of view, some programming languages encourage designing the software top-down, always breaking problems into smaller pieces, and then implementing the software bottom-up. I take <a href="http://www.forth.org/">FORTH</a> as an example, in which it is near to impossible to write even slightly complicated software without designing it thoroughly in a top-down fashion first. Most languages, such as Java or C, don&#8217;t really force you to manage complexity in any way, but merely provide you with the tools.</p>
<p>There are a lot of ways to bind all your software components so tightly together that there&#8217;s soon no way to take them apart anymore. One way is having a so called &#8220;<a href="http://en.wikipedia.org/wiki/God_object">god class</a>&#8220;, a class usually aptly called something like &#8220;World&#8221; that ends up having most of the code in the project. Other popular ways include global variables, static variables or simply functions that are 1000 lines long, with multiple static variables that are conditionally used for different purposes in the beginning, middle and end of the function. Here are some small hints how such misfortunes can be avoided.</p>
<p>One thing to keep in mind is that each class, function and module should have exactly one well defined task to do. When I put it that way it sounds almost trivial, but it&#8217;s still sometimes forgotten. Another problem that I often see are confusing interfaces: when designing the interface, don&#8217;t have functions InitTaskX(), BeginTaskX() and StartTaskX(), where StartTaskX() internally calls InitTaskX() and BeginTaskX() in sequence. Instead rather decide on one option that the one using the interface will need (even when it&#8217;s &#8220;future you&#8221; &#8211; in a few weeks you&#8217;ve forgotten what you meant with all the weird functions anyway) and stick to it.</p>
<p>Another thing I wanted to use to increase modularity in Freekick was to split the whole application in multiple processes. There&#8217;s one process for doing all the non-soccer-match stuff &#8211; menus, league tables, transfers, etc. and other processes for the actual match. When the main menu process starts a match, it creates an XML file for the match server, then starts the server and passes this XML file to it, then starts the other match-related processes (client and AI). This allows me to be 100% sure that I can change anything in the menu part of the application and not break the actual match, as long as I don&#8217;t change the XML file which serves as the interface between the two.</p>
<p>The server itself handles the physics, rules and the match state, while the clients display the state received by the server and send user input to the server. As a nice bonus adding multiplayer capability is relatively easy, even though it was something I hadn&#8217;t originally planned. Another positive thing about it is that I can use different programming languages for different processes; I&#8217;m currently writing the menu part in Python and the actual match part in C++. There are also more sophisticated libraries for accomplishing a similar task, such as <a href="http://www.freedesktop.org/wiki/Software/dbus">D-Bus</a>, but I felt it would&#8217;ve been an overkill for this one.</p>
<p>As for the server and the clients, they communicate over a simple, clearly defined Freekick protocol that works over network sockets. This allows me to change the way the client displays the match, for example, without me being able to break the functionality in the server. In Freekick, the AI is a client as well, which allows me to reuse much of the client code while still having clear limits on what code belongs to the client that the player sees, what is only relevant for AI and what code is used by both of them.</p>
<p>Splitting the game into a server and a client is what <a href="http://freeciv.wikia.com/wiki/Main_Page">FreeCiv</a> did as well, by the way. That&#8217;s why there exist multiple clients for FreeCiv that do the same thing but look different. Freekick has two clients now as well, one that shows the match  in 3D and another where all the graphics are text based, using <a href="http://www.gnu.org/software/ncurses/">Curses</a>. In the end they both same exactly the same soccer match with the same AI, logic, state and rules, only the way of displaying it and receiving input from the user different.</p>
<p>As for the internal structure of the server itself, I&#8217;ve also tried to keep things as independent from each other as possible. There&#8217;s the Physics class, which is a <a href="http://en.wikipedia.org/wiki/Facade_pattern">facade</a> to the whole physics subsystem. Then there&#8217;s Rules, a class that is responsible for calculating the changes in the current rules status of the match. Physics can be subscribed to, implementing the <a href="http://en.wikipedia.org/wiki/Visitor_pattern">visitor pattern</a>, and is subscribed by Rules. Rules receives all updates from Physics (where the ball is at the moment, which player touched the ball, etc.) and updates the rules state correspondingly.</p>
<p>Rules can be subscribed as well, and both of these classes are subscribed by Dispatcher, a class that sends both kinds of updates, rules and physics, to the clients. How does Dispatcher know who the clients are? There is the class ServerManager, which accepts incoming connections and adds them to the list, which the Dispatcher has a pointer to. There are also classes ClientEventListener that receives the input from the clients and InputMonitor, which validates the data before passing it on to Physics.</p>
<p>Freekick is using <a href="http://www.bulletphysics.com/Bullet/wordpress/">Bullet</a> for physics simulation. While Bullet is an excellent library, I can&#8217;t be sure Freekick will be using it forever (who knows what kind of open source physics libraries we have in five years). To make sure the physics engine can be exchanged in the future as easily as possible, I wrote an interface that should correspond my needs and no more &#8211; functions like addStaticObject(form, position) and simulate(timestep) &#8211; a <a href="http://en.wikipedia.org/wiki/Adapter_pattern">wrapper</a>. The interface is then implemented by the BulletPhysicsEngine class using the sometimes not-so-clear Bullet interface.</p>
<p>These are some ways to add modularity in software &#8211; of course, there are more and maybe better ways to do it, but these have made it rather easy for me to continue implementing Freekick, even as the code base has gotten bigger with time. For the interested, the Freekick code itself can be browsed <a href="http://github.com/anttisalonen/freekick/tree/master">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=40&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2009/03/12/40/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>
	</item>
		<item>
		<title>Freekick news: single player mode and first menu drafts</title>
		<link>http://codeflow.wordpress.com/2009/02/22/freekick-news-single-player-mode-and-first-menu-drafts/</link>
		<comments>http://codeflow.wordpress.com/2009/02/22/freekick-news-single-player-mode-and-first-menu-drafts/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 16:15:45 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[game ai]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[pyqt]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[soccer game]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=37</guid>
		<description><![CDATA[Time for a small update again. The last time I wrote I mostly reviewed the work done last year, wrote about the tools used and spent some time comparing Haskell with C++ as I had been busy rewriting the Freekick server in C++. So what&#8217;s been going on in the past month? Well, some of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=37&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Time for a small update again. The last time I wrote I mostly reviewed the work done last year, wrote about the tools used and spent some time comparing Haskell with C++ as I had been busy rewriting the Freekick server in C++. So what&#8217;s been going on in the past month? Well, some of the points mentioned in &#8220;things to do next&#8221; part of the last post have been worked on, while others aren&#8217;t. Also, as I have now been using C++ for a few months there have been some signs of the need to wander off to another &#8211; hopefully better and shinier &#8211; programming language again, just like one would expect. This time I&#8217;m not thinking of Haskell though, but <a href="http://www.python.org/">Python</a>.</p>
<p>I&#8217;ll first let you know what&#8217;s new with Freekick core development. There&#8217;s been a lot of small improvements &#8211; I&#8217;ve added some server functionality such as allowing human players to play along or goal detection, but the most important update is that the OGRE client now has the ability to control a player and kick the ball around. This actually makes Freekick a soccer game that can be played. This doesn&#8217;t mean, however, that it would actually be fun to play the game &#8211; the relatively silly AI makes sure we&#8217;re not quite there yet. Another thing that makes the game less fun is that the clubs aren&#8217;t really there; the players have no differences in skills or personality, there are no kits or club names or tournaments.</p>
<p>The next thing for me to do is try and eliminate these two problems: first, the AI needs to be made better. At the moment it&#8217;s not really <strong>that</strong> bad &#8211; they pass the ball and try to score &#8211; but they only have a few actions which makes the match seem repetitive, and the goalkeepers are horrible. Second, the soccer match needs to have a menu around it, including creating and viewing tournaments, lineups, league tables &#8211; the whole deal. Actually I&#8217;ve already started work on that, which brings me to Python.</p>
<p>You see, working with C++ the whole time with Freekick core was not bad, but after you&#8217;ve seen something like Haskell in action, sooner or later you start to wonder if everything really needs to be so complicated. I&#8217;m talking about the sheer amount of time spent typing the code in, the loops, the iterators, the classes and headers and declarations, the curly brackets&#8230;</p>
<p>As Freekick was designed with modularity in mind and was split to multiple processes from the beginning on, the question of using Python for the game menu arose. After poking around with <a href="http://wiki.python.org/moin/PyQt">PyQt</a> for a while the first drafts of the game menu were already finished. I had had my doubts about dynamic languages and duck typing before, but now, after having written a few small applications with Python I&#8217;m slowly starting to see the advantages such a dynamic high-level language can bring. I was amazed how fast you could actually write a simple-looking Python script that does the same thing as an application you could spend weeks writing in C++.</p>
<p>Encouraged by my Python adventures, I played around with the idea of solving the other problem &#8211; AI &#8211; with Python. Since I don&#8217;t really fancy writing all the Freekick client side logic in Python, I thought about using <a href="http://www.boost.org/doc/libs/1_38_0/libs/python/doc/index.html">Boost.Python</a> to export the C++ classes into Python. Doing the <a href="http://github.com/anttisalonen/freekick/tree/a37e04c6b8ffbf85addb4f8c8e962da0f83d1f43/src/freekick/match/client/python">experiment</a> was interesting, but the unfortunate truth is that exporting the classes still seems like too much work, even with the excellent library, especially with the page-long error messages and the fact that the STL containers would apparently also be have to exported <a href="http://wiki.python.org/moin/boost.python/StlContainers">manually</a>. The other way would be <a href="http://www.python.org/doc/2.5.2/ext/lower-level-embedding.html">embedding Python</a> in C++, but I&#8217;d still have to export the data structures to Python and back, which makes me think it&#8217;s probably faster just to stick with C++ after all.</p>
<p>The GUI part is still far from ready &#8211; the only event that starts a match at the moment is a friendly match, and the GUI-match interface is non-existent at the moment &#8211; but the base is there and will be expanded when the time is ready. At the moment I think improving the soccer match itself is more important, since there is really no good reason to start a match if playing it isn&#8217;t fun, which brings me back to C++ and the AI. I&#8217;ve been reading the book &#8220;<a href="http://www.amazon.com/Programming-Game-Example-Mat-Buckland/dp/1556220782">Programming Game AI by Example</a>&#8221; by Mat Buckland again, which really is quite an inspiring work, but I think it will still take a while for me before the AI code is in a state where it both seems halfway smart and is easily extensible.</p>
<p>Luckily there are still a couple of mini projects for me to do in case writing AI gets boring. First of all there&#8217;s the GUI with all the tournament and schedule creation to do, but I think the time is also slowly getting ready for another Freekick client, this time with <a href="http://www.gnu.org/software/ncurses/ncurses.html">ncurses</a> as the &#8220;graphics&#8221; library. I&#8217;ve been wanting to get my hands dirty with ncurses for a while now, and I&#8217;m all for minimalistic software, so hey, why not. Other fun things include creating a TV style soccer camera in <a href="http://www.ogre3d.org/">OGRE</a> and taking player skills into account on the server side. I&#8217;ll keep you posted.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=37&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2009/02/22/freekick-news-single-player-mode-and-first-menu-drafts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>
	</item>
		<item>
		<title>Freekick the C++ way</title>
		<link>http://codeflow.wordpress.com/2009/01/10/freekick-the-c-way/</link>
		<comments>http://codeflow.wordpress.com/2009/01/10/freekick-the-c-way/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 12:00:04 +0000</pubDate>
		<dc:creator>Antti Salonen</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[bullet]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[ogre]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[scons]]></category>
		<category><![CDATA[soccer game]]></category>

		<guid isPermaLink="false">http://codeflow.wordpress.com/?p=34</guid>
		<description><![CDATA[New year, new tricks. In this post I&#8217;ll explain what Freekick has been doing for the last two months. The main events include rewriting Freekick in C++ so that it finally matches the Haskell version feature-wise, as well as gaining a bit of experience in using the associated tools and libraries. Before I get to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=34&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>New year, new tricks. In this post I&#8217;ll explain what Freekick has been doing for the last two months. The main events include rewriting Freekick in C++ so that it finally matches the <a href="http://www.haskell.org/">Haskell</a> version feature-wise, as well as gaining a bit of experience in using the associated tools and libraries. Before I get to that, let me first write down a brief summary of the last year, and of the blog thus far.</p>
<p>In <a href="http://codeflow.wordpress.com/2008/04/23/whats-this-blog-about/">April</a> I wrote the first post announcing the beginning of the project, wondering which language and graphics library to use. The decision was in the end to go for C++ and <a href="http://www.ogre3d.org/">Ogre</a>. I was also preparing <a href="http://www.cegui.org.uk/">CEGUI</a> as the GUI library. The build system was make, the version control system used was <a href="http://subversion.tigris.org/">Subversion</a> (if any).</p>
<p>In <a href="http://codeflow.wordpress.com/2008/05/18/a-break-from-ogre/">May</a> I got to physics libraries and decided to look at <a href="http://www.ode.org/">ODE</a> instead of <a href="http://www.bulletphysics.com/">Bullet</a>. Soon after that I&#8217;d let the physics and graphics digest for a while and learn Haskell instead as a tool for AI programming.  Back then, there was no real code written for the project yet.</p>
<p>In <a href="http://codeflow.wordpress.com/2008/06/18/haskell-a-grain-of-python/">June</a> I had learnt the basics of Haskell and was using it to program some of the first things in Freekick.</p>
<p>In <a href="http://codeflow.wordpress.com/2008/07/12/about-designing-software/">July</a> the very basic design of Freekick was slowly getting clear. The plan was (and is) to split the game to different processes and use a server-client model. I went on programming the server and the AI in Haskell and played with the thought of writing the client in <a href="http://www.python.org/">Python</a>. I also started getting VCS conscious and mentioned <a href="http://darcs.net/">darcs</a> for the first time.</p>
<p>By <a href="http://codeflow.wordpress.com/2008/08/03/about-ai-and-neural-networks/">August</a> I had gotten as far as programming some multithreaded networking in Haskell, as well as doing some nice experiments and tests with neural networks. While the networking part was directly a part of Freekick at the time, I haven&#8217;t integrated the concept of neural networks with the project yet.</p>
<p>In <a href="http://codeflow.wordpress.com/2008/09/19/a-few-more-words-on-freekick/">September</a> the very basic structure of Freekick, including the server, AI and a client, was finished in Haskell and the version 0.0.1 was released. The client was written using <a href="http://www.libsdl.org/">SDL</a>, the primitive physics for the server was done without external libraries and the AI was a simple decision tree.</p>
<p style="text-align:left;">In <a href="http://codeflow.wordpress.com/2008/10/18/on-haskell-and-c/">October</a> the negative sides of Haskell were starting to become clear, mainly being problems with the performance and problematic use of C++ libraries. The decision was to write a new client in C++ that uses Ogre for graphics. Implementing the data structures (classes) in C++ for the client also makes writing the server in C++ not such a big step.</p>
<p>In <a href="http://codeflow.wordpress.com/2008/11/10/fun-with-ogre/">November</a> the new client was finished. As it became clear that the performance problems had more to do with the Haskell server than with the client, the decision was to rewrite the server in C++.</p>
<p>In December I didn&#8217;t have the time to write about it, but I was busy rewriting the server in C++. This included updating the protocol between the server and the client as well as learning object oriented design.</p>
<p>And now, in January, it&#8217;s time for a post again. The C++ server is running, and the preliminary AI is finished too. As there were some updates to the Freekick protocol that broke the backwards compatibility; the old Haskell programs (server, SDL client, AI client) would have to be updated to match the new protocol in order to be able to work with the newer software (maybe I&#8217;ll get to it on some rainy day).</p>
<p>As there are some difficulties finding a public code hosting site for darcs repositories (and darcs seems to have <a href="http://hackage.haskell.org/trac/ghc/wiki/DarcsEvaluation">some other problems</a> too), I went for another RCS, namely <a href="http://git-scm.com/">git</a>. I too am one of those who don&#8217;t want to go back to centralized SCM after seeing the other side, and git seems to fit my needs perfectly. The Freekick code can be found at <a href="http://github.com/">GitHub</a> by the way, at <a href="http://github.com/anttisalonen/freekick/tree/master">http://github.com/anttisalonen/freekick/tree/master</a>. If you want to compile and run it though, there are some external dependencies (notably Bullet and Ogre) and the build script probably isn&#8217;t portable yet. If you run into problems, drop me a note.</p>
<p>As a side note, I <a href="http://lwn.net/Articles/188693/">also</a> wondered <a href="http://freshmeat.net/articles/view/1715/">which build tool</a> to use for the C++ version of Freekick (for Haskell, <a href="http://www.haskell.org/cabal/">Cabal</a> is the excellent build tool, while C++ has a lot more options). The two strongest candidates were <a href="http://www.cmake.org/">CMake</a> and <a href="http://www.scons.org/">SCons</a>, and in the end I went for the latter. The build tool for Freekick has the seemingly complicated task of compiling and managing a few libraries and applications, preferably comfortably configured in one configuration file. By now, my SCons build script (SConstruct) has become about 150 lines, but it does everything I want it to and how I want it to. The level of documentation for SCons is also excellent.</p>
<p>Now, a few words about implementing Freekick. First of all, even though C++ is more comfortable than I previously thought, it&#8217;s still far away from Haskell. My impression is that, thanks to the <a href="http://www.boost.org/doc/libs/1_37_0/libs/libraries.htm">Boost libraries</a>, you can use most of the nice things that Haskell has (e.g. tuples, lambdas), and everything will run slightly more efficiently than in Haskell, but there&#8217;s a lot more code to write and the code is a lot less elegant and a lot more verbose than in Haskell. I guess the better control of CPU cycles and bytes of RAM is worth it.</p>
<p>An interesting thing to note is that it took for both Haskell and C++ about three months to implement the basic functionality of Freekick. The comparison is unfair; I had just learnt Haskell when I started programming Freekick with it, while I&#8217;ve had previous (albeit now rather obsolete) experience with C++. Also, when I programmed Freekick the first time, the basic structure and design was only barely clear to me. With Haskell I had to program my own primitive physics engine, with C++ I used Bullet (which was about just as troublesome). The Haskell graphical client was easily done in SDL, while the Ogre client was a bit more work (though using Ogre is actually quite fast, easy and fun &#8211; signs of an excellent library). However, in the end the difference in development times wasn&#8217;t drastic, which shows to me that C++ really seems to do the job of evolving to a higher level language with time pretty well.</p>
<p>This was also the first time that I&#8217;ve actually done some object oriented design. It&#8217;s actually quite fun. The constant shuffling around with the header and cpp-files and the verbosity of it all is something I wouldn&#8217;t miss with Haskell, and the generic programming and code reuse that OOP offers is still light years away from the level you can find in a functional programming language. Still, C++ is on any account usable and I really need those cycles and bytes. Hopefully in a few years I can use a language that is as elegant as Haskell, while still maintaining the perceived efficiency of C++.</p>
<p>The next things to do with Freekick include relatively small improvements to the server (better compliance with the rules of the game), to the AI (it&#8217;s really quite primitive at the moment) as well as to the client (controlling a player and some small graphical enchancements). After that the next task is to go and implement the bigger plan, i.e. the game around the match &#8211; organizing the matches into cups and leagues.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeflow.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeflow.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeflow.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeflow.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/codeflow.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/codeflow.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/codeflow.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/codeflow.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeflow.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeflow.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeflow.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeflow.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeflow.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeflow.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeflow.wordpress.com&amp;blog=3671090&amp;post=34&amp;subd=codeflow&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codeflow.wordpress.com/2009/01/10/freekick-the-c-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/faafc62304db9501ac09283a7f19da97?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anttisalonen</media:title>
		</media:content>
	</item>
	</channel>
</rss>
