November 2014

S M T W T F S
      1
234567 8
9101112131415
16171819202122
23242526272829
30      

Style Credit

Expand Cut Tags

No cut tags

October 21st, 2014

overworldtheme: (programming)
Tuesday, October 21st, 2014 02:51 pm
[Cross posted from the Vision Riders Blog.]

Last night in bed, as I was thinking about things that still need to be done for my next game before I can really start diving into it, I began thinking about the scripting engine. Another Star just hard-coded all scripting in C#, but, for one, there's no way I'm scripting scenes in C++, and two, it's really tedious to hard code script even in C#.

As I thought about the scripting language and how I could store all the script in files, I came up with the idea of packing all the scripts in one file. In the file header would be a table of all the individual scripts with their locations and sizes within the file, so I could load only what I need at a time.

And, since I want the language to be case insensitive anyway, I figured I could probably save some space by reducing each character to just six bits. Six bits gives enough for only a subset of ASCII. 64 characters, to be exact. And you want to convert lowercase letters to uppercase letters (or vice versa) so you don't waste an extra 26 of those precious characters on just letters. With six bit characters, you can do what's called packing. This is a form of data compression where you shove four six bit characters into three bytes, where normally each ASCII character would need a full byte each. Reduces the file size by exactly 25% right off the bat. Well, not counting the file header and such, but that's only a minute portion of the file.

Granted, there's really no need to save 25% by compressing a text file. I mean, really now. It's highly unlikely that all the scripts in the entire game combined together will amount to much more than a megabyte or two, if even that. But it's something I could do if I wanted to, nonetheless.

Then, I began to wonder if I could compress it even further. Five bytes per character! Eight characters would fit into every five bytes! Mwa, ha, ha, ha! I'm a madman!

Thing is, it can be done, and it can be done without a lot of "shifting" like in old-timey standards such as Baudot code.

Click here to continue reading and find out how )