More file preloading

June 8, 2008 by bbarrett

This is a bit of a follow up from my previous post.

In the end I decided to do preloading for Lua scripts too. This is because of the nature of my game - there are a number of times a Lua state (or interpreter instance) can be created. There is one for every “game”, plus a different one for configuration. When the executable loads, there is a dummy “game” playing behind the menu that creates a nice background animation. When the user selects “new game” - a new “game” instance is created.

Because most of the scripts are referenced dynamically from Lua via the “require” standard library function I wrote a function that replaces the vanilla require - it will look in the cache first and if it fails it falls back to the standard library function (which is saved in the Lua registry - a neat little hiding place for Lua values that the C API can access but the Lua scripts can’t. I haven’t tested it fully, but it appears to work well so far. Which obviously means there is something hideously wrong with it…

Freedom

June 5, 2008 by bbarrett

Long time no post. Well, I am finished my degree now, so that - theoretically - should leave time for some projects.

Content for once

So, I made a little progress during the week. I was playing my Asteroids game from a USB pen and it really showed me how my dynamic loading of files was slowing me down. Due to the way I wrote the game, nothing is preloaded (because all graphics and audio files are referenced from external scripts). They are loaded on demand. They were cached once loaded however. On my laptop hard drive, the delay is slight, but still perceptible. I must have gotten immune to it somehow - but since the USB pen thing I started to notice it more and it irritated me.

I wrote a little function that can be called from Lua (a running theme) that takes a directory and a function. It applies the function to every file in the directory and its subdirectories. The function is called with two arguments, the path to the file and a file size. The code for doing this is quite simple - I used the opendir() and readdir() POSIX functions, along with stat() to determine whether to recurse into a directory or to get the byte size of a regular file.

From Lua then I just loop across the data directory, and preload files that look like images or sound files. I haven’t yet implemented preloading lua files, and I’m not sure if I will (given that the majority of the are referenced by the script running the preloader). I’m thinking of breaking the script in two - one that is run at program launch and another that is run at “new game”. At the moment the same script handles a bit of both. I might consider using file watches (or listeners, or whatever they’re called) so I can be notified when a Lua script changes and reload the data, but that is far less likely.

Next up, some kind of graphical progress bar, rather than just using the window title text…

Alive… barely

May 14, 2008 by bbarrett

I haven’t updated in quite a while. Still, I almost have an excuse. I’m finishing my degree this year, and as such the last month or two has been a blur of projects and exams. I’ve just started the final exams, which will go on for the next two weeks. Perhaps then, and when I’ve had a little time to get some proper sleep, I’ll start posting actual content again.

Until then…

softness is necessary

April 5, 2008 by bbarrett

I finally got a more complex scene to look good with soft shadows. The problem was that area lights don’t seem to play nicely with my planes when they are reflective. I’ll show a comparison here.

This one doesn’t have any softness, but it has speed.

no soft shadow

This next one has softness, at the expense of a little speed :)

soft shadows

18 seconds vs ~60 minutes. Just a tad slower.

The lack of anti-aliasing is exaggerated by squashing the image. I really should do something about that…

Busy, Busy, Busy.

March 31, 2008 by bbarrett

Lately I’ve been busy. I am getting close to the end of my degree and I am currently struggling to get projects to work before they become due (I have 6 ongoing at the moment). Despite that, I have made minor progress with both my ray tracer and my Asteroids game. Videos, screenshots and other goodies follow.

Read the rest of this entry »

Texture mapping and cursing C++

March 17, 2008 by bbarrett

struct Texel
{
    Texel(float u, float v) : u(u), v(u) {}
    float u, v;
};

Yeah, look carefully. Both u and v are the same, and you spend quite a while wondering why you get renders like this:not a great picture at allThe only consolation is that when you’ve fixed the problem, you get something like this:

nice picture

That pretty map of the world came from the wikipedia, and appears to be free for any use. In case anyone is going to call me up on my statement last time, the C++ counts as content ;)

Some videos of my ray tracer in action

March 13, 2008 by bbarrett

I promise I’ll make more of an effort to include actual content next time rather than try dazzle people with style. Here is a relatively nice video of my ray tracer in action:

A perfect example of what not to do (i.e. ramp the reflection from 0% to 100%):

Ray traced images are amazing

March 4, 2008 by bbarrett

Sometimes, I wonder why I bother. Then my program produces an image like the below, and I get inspired again.

ray traced images

Parallel Processing

February 29, 2008 by bbarrett

This week I’ve added another piece to the puzzle that is my ray tracer. As you may have guessed from the lack of pretty pictures, by initial enthusiasm for the ray tracing part itself has waned a little, I’m trying to implement other parts that are interesting to me. In my ongoing effort to reduce the amount of time to draw, I wanted to make my ray tracer capable of running across a networked cluster of computers. I am thinking of eventually making the ray tracer output some kind of video or animation file, but that is a long time away yet. When that is done, I might attempt some optimisation of the ray tracing algorithm itself.

Read the rest of this entry »

More Lua based shenanigans

February 2, 2008 by bbarrett

I did some more work this week, on my ray tracer. Prior to this, the scene that would be rendered was static data compiled into the executable. This is understandably a bad idea because it requires the entire program to be recompiled every time I wish to change the scene. I decided to place the configuration in Lua, being one of my favourite languages. This gives me flexibility in many ways. I have plans to alter the program such that it will generate a continuous animation rather than static images. By using Lua, I can have a callback function that will move the camera or the objects between frames.

Read the rest of this entry »