Friday, November 23, 2007

Adding support for reading and writing the cache to disk

This week, I have been working on adding the ability to write the Deadwood-2 cache to a file, and read the Deadwood-2 cache from a file. Support for writing the file is complete. The file is very simple, and has the following format: For each element in the cache, write the key string to the file, followed by the value string object, followed by a 64-bit timestamp of when this record expires. Put less important (more likely to be deleted) elements at the beginning of the file and more commonly accessed cache elements at the end of the file (The reason for this is, when adding elements to the cache, more recently added elements are considered more important).

The string object has a very simple format in the file: A 32-bit big-endian length value, which must be a positive signed number (negative signed numbers mean the string has a length of 0), followed by the binary string. The timestamp is a representation of the 64-bit timestamp used by Deadwood, whose epoch is when the episode "Gambit" of the Blake's 7 television programme was first broadcast. Each second has 256 "ticks".

I have also fixed a bug in the hash used by the cache (it took me a couple of hours of fiddling around with Deadwood to find and get rid of it).

I'm also playing around with Doom Builder, an open-source Windows-only (Why doesn't Linux have a decent Pascal compiler?) program for editing maps. It's very easy to learn and use; I'm using it to make changes to a 9-map megawad generated by Oblige (for Heretic) in to one suitable for single player, deathmatch, and coop play.

I'm having a lot of fun with it; I just wish I had some buddies down here in Mexico to deathmatch with.

- Sam