This week has been slow programming wise. I added/changed a few minor things on my Asteroids game. I also did most of a project for college.

The big news for me is that I have secured the services of both graphics and sound artists for my Asteroids game. When the various media are finished then I will be able to release it.

I have another project in progress, one that will probably get a lot more of my attention now that my Asteroids game is coming to a close. It is a ray tracer. This, of course, gives me an excuse to post a screen shot.

raytracer screenshot

As you can see, I have reflection working, and multiple lights. It only handles spheres and planes of various colours and properties (reflectivity, etc). I had code for shadows, but removed it when adding multiple lights. I have a lot more I want to add to this.

Everything I add to this makes it slower to render. At first, I could render at near realtime speeds. But now it can take up to ten seconds to render a single frame, and I haven’t even gone beyond the basics yet.

Ever since I bought my dual core laptop just over a year ago I have been searching for a project to make multi-threaded. So I tried. I use SDL for the pixel plotting, window management and miscellaneous other things. SDL has a capable threading API. My first attempt (running theme?) was a miserable failure. Locks all over the place, but the threads didn’t synch correctly. Each thread grabbed a pointer to the screen and wrote directly to it. I wasn’t really thinking about the code at the time – just the usual “get it done, figure out how to do it right later” that I often slip into. Not that that is necessarily bad all the time, but concurrency issues need some thinking on.

In the end, the correct answer came to me after some sleep. It was obvious in retrospect: producer/consumer. Instead of having each thread use a pointer to the framebuffer, each auxiliary rendering thread independantly generates new SDL_Surfaces, fills them and passes them to the main thread. A little used fact of the SDL event system is that SDL_PushEvent() is thread safe. Combine this with user defined events and I had everything I needed. Now my ray tracer draws twice as fast on my laptop. Now, to add something new to it to slow it down again…


One Response to “progress?”

  1. Looking good. Can’t wait to see what additions come next. 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: