eVoid Development Weblog Burn The Land And Boil The Sea But You Can't Take The Sky From Me

21Jul/100

C++0x, Lambda Expressions and Visitors

I know there are thousands and millions of articles out there dealing with the new features that are being introduced by the new C++ ISO standard commonly known as C++0x. Today I read that on Code Project and got very enthusiastic about the part that described the lambda expressions. I know that is damn geeky but I almost went bananas :D when I read what they are and what kinda stuff you can do with them. Countless situations came immediately on my mind in which I could take advantage of them. Usually I tend to make very extensive use of the Visitor pattern. Most of my classes that encapsulate some kind of an 1 -to- n>1 association do offer a function like VisitObjects( :UnaryFunction ). I like it that much because I believe it's the most short and abstract way to offer an interface for the traversal of associated objects. No matter how the data is internally organized - whether it's a tree or maybe a flat structure like a linked list or an array - the interface stays all the same. Up to now I had to do the following to make use of that kind of interfaces:

namespace impl
{
 
class MyFunctor
{
public:
 
    int i;
 
    MyFunctor( int i )
        : i( i )
    {
    }
 
    bool operator() ( const MyElement& e )
    {
        std::cout << ( i++ ) << " - " << e << std::endl;
        return true;  //< continue traversal
    }
 
};
 
}  // namespace impl
 
 
void MyClass::MyFunction()
{
    impl::MyFunctor visitor( 0 );
 
    MySet.VisitMyElements( visitor );
 
    std::cout << "We've vistited " << visitor.i << " elements" << std::endl;
}

Everyone will admit that is kinda ugly. Now, thanks to lambda expressions, I could just inline the whole logic into the one really necessary function:

void MyClass::MyFunction()
{
    int i = 0;
    MySet.VisitMyElements( [&]( const MyElement& e )->bool
            {
                std::cout << ( i++ ) << " - " << e << std::endl;
                return true;  //< continue traversal
            } );
 
    std::cout << "We've vistited " << i << " elements" << std::endl;
}

Though I haven't tested it, to me lambda expressions and the visitor pattern seem like made for each other :D

  • Share/Bookmark
5Jul/102

Update + Thoughts of Quad- & Octtrees

Even though I didn't update that blog during the past few months, the work proceeded quite well. A countless amount of bugs has been fixed, the abstraction from OpenGL improved a lot and the API itself completely revised. I've outlined a road map of what still has to be done 'til Alpha 2 and it's not that much:

  1. Implement DefaultMesh::CreateSphere
  2. Implement DefaultMesh::CreateCylinder
  3. Implement DefaultMesh::CreateCone
  4. Solve Bloom-zBuffer-Problem
  5. Clean up some header files

So #1 was an ease and now I'm still almost done with #4 which is the last greater task. The problem here was that rendering with bloom worked like a charm but when rendering in combination with objects that should have been not affected by the bloom effect, the depth-buffer information messed up. The bad thing about it is that I finally reached the limits of the possibilities of my GeForce 6600 and am not able to proceed right now, for I also don't have the money to buy me a new card. So it's fairly probable that I won't continue work on this task until September, when I expect to get a new notebook bought by the institute I will start working at, namely the Institute for Medical Engineering as an appliance.

So I spent a few thoughts on the later organization of the world data in octtrees recently when I was bored. The following short article will describe a way of organizing the nodes of a quadtree (for the sake of clarity) in a certain way which allows a very easy and straightforward traversal of the tree. It is trivial to expend this technique to work with octtrees.

  • Share/Bookmark
7Sep/080

Walheim, 8. September 2008

  • Share/Bookmark
3Sep/080

Walheim

  • Share/Bookmark
22Nov/070

Gentoo Desktop mit Compiz-Fusion

Ausführlich hier dokumentiert.

  • Share/Bookmark
10Sep/060

Altitude Map

In den vergangenen Wochen habe ich mich etwas tiefgehender mit der Funktionsweise von Geländegeneratoren beschäftigt und selbst einen in C++ implementiert. Dabei habe ich primär vom Subdivision-Algorithmus Gebrauch gemacht - Im Prinzip teilt dieser die zu erzeugende Höhenkarte in immer kleinere Rechtecke auf, indem der Mittelpunkt des ursprünglich gewählten Vierecks als Eckpunkt von vier neuen Vierecken interpretiert wird. Dieser Mittelpunkt wird um einen zufälligen Wert, der aber nach bestimmten Gesetzen ermittelt wird, angehoben. Auf diese Weise, und um einige zusätzliche Mechanismen, wie z.B. einem Erosionsalgorithmus, erweitert, lassen sich interessante Gelände generieren.

  • Share/Bookmark