Sunday, April 30, 2006

Portability games

I found out why the sky wasn't working: it turns out that q2bsp (the new name for qbsp3) gets the flags that tell it if a face is part of the skybox by reading the headers of the texture files. It wasn't able to load the textures, so it couldn't work out that the sky-textured bits were actually sky.

One thing led to another, and I ended up rewriting not only the PAK loader, but just about all the code that messes around with filenames and directories.

A PAK file is basically a linear collapse of a directory tree into a binary object (it's entirely uncompressed) and I believe that the reason for doing it was to avoid the overhead of opening, reading and closing a lot of files. Anyway, in order to find a file such as a texture, the tools need to look in up to four different places, including scanning through PAK files containing thousands of files. I decided that it would be fairly straightforward to get rid of the necessity of scanning for files more than once: the tools now scan through all the places textures could be as they start up, and store the locations of the files in a hashtable, along with the file pointer of the PAK file they're in. So not only do I only read the header of each PAK file once, I only do a full scan once, and after that its just an O(1) lookup to find a file.

Anyway, the upshot of this all is that all the tools now compile and run without errors on Windows/Cygwin and on 64-bit Linux, and even create playable maps! Get the latest release now, and tell me about any problems you find.

Except q2rad, that is, because the default settings of q2rad are rubbish -- they leave the map totally unlit. Oh, for the ability to merge my code with ArghRad...

Wednesday, April 26, 2006

And progress continues apace

I think I've finally cracked the maths behind the Brush Primitives format, which is a good start. I've written it up on the buildutils wiki. Now I just need to work out the maths behind the other two formats that I need to support (Classic Quake and QuArK ETP) and all will be well.

I took the time to move the tools over to using GNU getopt to parse command line options -- something I've been meaning to do for a while, because not only is it easier to maintain, but it needs a lot less code: you can see what each of the command-line options do at the code level much more easily now.

I also renamed them: the package is now buildutils-q2bsp and the four tools are q2bsp, q2vis, q2rad and q2bspinfo.

I have, however, just noticed a somewhat worrying problem. When I load a map I've compiled in Quake II, the sky doesn't work; I just see a flat texture. However, when I load one the Quake II game proper (for example), the skybox works just fine. I'll investigate further, but not now because it's the middle of the night...

Monday, April 24, 2006

Quake II tools update

Well, it's a while since I posted on the subject of compiling maps for Quake II, but I'm pleased to announce that things have started moving again. I was contacted yesterday by whitelynx of the Precursors project, asking what was going on.

Anyway, one thing lead to another, and now there's a Trac site for the project: wiki, subversion repository and bugtracker. I'm very grateful to for the hosting (AutoPackage is hosted on the same server, I was suprised to learn). However, the package will continue to be distributed from here.

whitelynx has decided that it would be a good idea to bring lots of different tools "under one roof", so the package is now called "buildutils", with the Quake II compilers called "q2bsp". The new name for the Quake II package is of course inspired by the Quake II build tool, "q3bsp" (which we're trying to get source code for as well). In fact, whitelynx wants to merge in tools for as many different games as possible; I think that's a bit ambitious, so I'm going to watch with interest.

I've made a few small changes in the last few hours; the tools now get linked against libm (which helps), and I've fixed all outstanding compile-time warnings on 64-bit Linux (yay). Lots of stuff to do still, though! I still need to implement Brush Primitives support, for instance...