Holidays

What does a computer science student do in his holidays when he is bored? Right! He plays around with http://irrlicht.sourceforge.net

boost::thread tutorial

I am working on a little 2D game engine right now and to make my life easier I took a look into the boost libraries. Especially boost::thread, which I’m going to write about and boost::statechart.

As I said before, I’m talking about boost::thread today and I assume that you have some C++ knowledge. I will create 2 classes. One class which creates the threads, a second class which inherits the threads. Finally in the main function we will use them.

The first thing you have to do is to include the boost header for boost::thread. In this case it is

Create a new file with a class inside, this time we call it BoostThread. Create a constructor and a virtual deconstructor, which you leave empty. For the constructor we create a private variable stopRequest and use it as inheritance for the constructor. As next we have to use the boost library. In the private part, create a boost::shared_ptr< boost::thread > newThread member.

1
2
3
4
5
6
7
8
9
10
class BoostThread {
public:
BoostThread() : stopRequest( false ) { }
 virtual ~BoostThread() {
 virtual void run() { } // execute the new thread inside here
 
private:
bool stopRequest;
boost::shared_ptr< boost::thread > newThread;
};

This is now a part of the basis we need to create a new thread.
We can not run it yet, because there are 2 functions missing.
Create int start() and int stop() as public functions. start()
has to look like this:

assert( !newThread );
printf( “starting boost thread\n” );
newThread = boost::shared_ptr< boost::thread >( new boost::thread( boost::bind( &BoostThread::run, this ) ) );
return 0;

The line newThread = boost::share…. creates a shard_ptr as you can see and binds BoostThread::run into it. Which means if you call the function start(), the thread will be created and executed. If you want a function with parameters such as start( string fileName ) you just create this function, a  string as private variable and instead of  boost::bind( &BoostThread::run, this ) you write boost::bind( &BoostThread::run, this, myVariable );

For stop() you write:
assert( newThread );
stopRequest = true;
newThread–>join();
return 0;
This will cause the thread to stop.

The class should now look like this:

class BoostThread {
public:
BoostThread() : stopRequest( false ) { }
 virtual ~BoostThread() {
 virtual void run() { } // execute the new thread inside here
 int start() {
 assert( !newThread );
 printf( "starting boost thread\n" );
 newThread = boost::shared_ptr< boost::thread >( new boost::thread( boost::bind( &amp;BoostThread::run, this ) ) );
 return 0;
 }
 
 int stop() {
  assert( newThread );
  stopRequest = true;
  newThread->join();
  return 0;
 }
 
private:
bool stopRequest;
boost::shared_ptr< boost::thread >; newThread;
};

This is it so far for the FIRST part.
Create a new class and I just call it TestClass. Inherit the BoostThread and create a constructor, the run function we have to inherit and one function called testFunction. Create a BoostThread *newThread as a private member.

class TestClass : public BoostThread {
 
    public:
    TestClass() { cout < < "Initializing a new Testclass" << endl; }
    // import run from BoostThread to create a new thread
    void run();
    bool testFunction();
 
    private:
    // create a BoostThread member
    BoostThread *newThread;
}

Ok, this is the class part so far. Now testFunction, run and the constructor need some code to run with. If you want you can leave the constructor empty, it is not important in this case. But I like to have a simple message for debug purposes so we write just cout < < "Initialize TestFunction\n"; inside.

For the run() function we do the same in this case. We write a simple message and that's it in this case. If you want you can execute sound code, network code or anything else inside this run function.

NOW the interesting part. The testFunction() turns out to start the thread. So we want to create now our newThread and execute the start() function from our BoostThread class.

bool TestClass::testFunction() {
newThread = new TestClass();
newThread->start();
return false;
}

The whole class code looks like this:

class TestClass : public BoostThread {
    public:
    TestClass() { cout < < "Initializing a new Testclass" << endl; }
    // import run from BoostThread to create a new thread
    void run();
    bool testFunction();
 
    private:
    // create a BoostThread member
    BoostThread *newThread;
};
 
void TestClass::run() {
    cout << "Running a new thread\n"; }
}
bool TestClass::testFunction() {
 newThread = new TestClass();
 newThread->start();
 return false;
}

The last part is very simple. I just created a main function, with a simple for loop and create threads inside the loop.

int main() {
    // our test
    TestClass newClass;
    // loop 10x and execute each time a new thread
    for( int i = 0; i < 10; i++ )
        newClass.testFunction();
    return 0;
}

ID Software Rage

It’s time to show at least something from the Quakecon 2009. ID Software showed their upcoming game based on the idtech5 engine “Rage”. This game takes place in a post-apocalyptic world and that’s about all they released on information.. Here it comes now: They released a trailer which shows in game footage of the game and I will not hesitate to hold it back.

Monkey Island

I know this news is too late because most of you people already know, played and finished the first part from Tales Of Monkey Island. Telltale announced a few days ago the release date of The Siege Of Spinner Cay, which is chapter 2.

http://www.telltalegames.com/community/blogs/id-485


PCSX2

About 2 -- 3 years ago I bought a used PS2 with a few games. One of the games was Final Fantasy X, which probably many of you people know. I finished this game about three times and still was impressed by it’s story. So I got the idea why don’t you try running it on your PC. The question was how and after some research I found the PCSX2 project So I tried to run this game on my old pc, which was an Athlon64 3000+ running at 3800+ and 2GB of DDR, followed by a Geforce 6800 GLH edition. I could run this game with about 5 fps including all graphical glitches the renderer could give me at this time.

However, I tried to run the game again with my new system. It is still sometimes a bit lagging and slows down, but the emulator made a big improvement up to today.

In this short recording, the video runs at 25fps. The game originally runs with 60fps with the emulator and so it won’t be running fluidly. One big advantage of the emulator is the possibility to skip frames, which increases the whole game speed at a time. You see it at some parts in the video, where it is running much faster than usual.Also you can choose the renderer and soundplugin. The renderer is especially good, since you can choose between directx9/10/11 software/hardware and OpenGL. The directx renderer comes with SSE2, SSE3 or SSE4, whatever your CPU supports.

A funny glitch is in some fights the characters are showing each others back and when you start an attack they are running backwards. I wasn’t lucky to get a shot of this but it is awesome funny to see that.

Deus Ex Renderer

I just found an interesting site where some people started projects on enhancing Deus Ex. New OpenGL, Dx9, Dx10 renderers

UT3

Still no UT3 for Linux… It’s been 2 years now…

No Time

Sorry just no time. University student so you know…

Mirror’s Edge

Did you play Mirror’s Edge? It’s an amazing game! Somehow it supports Ambient Occlusion with the 185 beta driver from nVidia. It runs with constant 60fps on my computer but after activating AO I was running and jumping around with 15fps -- 25fps.  But it’s a difference in graphics. I made a short video of this. It’s short because I play at 1680x1050 and it’s size was 1.5gb for 1 min 20 sec. After using TMPGenc and CUDA (such a great technology) I got a little video done and upped it on youtube. The decoding process took about 2 minutes with CUDA. With my 8 cores about 20 minutes.

The Spoony Experiment

While I was surfing through the Internet watching for game reviews I found a funny guy making his own reviews about games, movies… well… I’m still laughing…

He plays the games and is looking deeper into the game play. Adding funny but true comments he shows the game play of different games.

Better you take a look at yourself.

Main Site

Game-Review