<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" 
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 
  xmlns:admin="http://webns.net/mvcb/" 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="http://www.sea-of-memes.com/rss.xml" rel="self" type="application/rss+xml" />
<title>Sea of Memes</title>
<link>http://www.sea-of-memes.com</link>
<description>Let's Code... an MMO!</description>
<dc:language>en-us</dc:language>
<dc:creator>mgoodfel@free-the-memes.net</dc:creator>
<admin:errorReportsTo rdf:resource="mailto:mgoodfel@free-the-memes.net"/>
<sy:updatePeriod>daily</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>2010-01-01T12:00+00:00</sy:updateBase>
<dc:rights>Copyright (C) 2012 Michael Goodfellow</dc:rights>

<dc:date>2012-05-16T19:00:00-07:00</dc:date>


<item>
<dc:date>2012-05-16T19:00:00-07:00</dc:date>
<title>Writing a Game</title>
<dc:subject>
I'm actually working some more hours this week.  Many things to do! 
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/Delay/Games.html</guid>
<link>http://www.sea-of-memes.com/Delay/Games.html</link>
<description>
I'm actually working some more hours this week.  Many things to do! 
</description>
<content:encoded><![CDATA[

<h2>Writing a Game</h2>
<p>
It's been nearly two weeks since the last post, and longer since I had anything with
substance.  This is just a quick note to let you know I'm not dead!
<p>
In fact, I'm working on the little mini-game that I started on in January.  I decided
it was worth brushing off and doing some more work on.  Here's a screenshot:
<p>
<table align=center>
<tr><td><img src="http://www.sea-of-memes.com/Delay/towers.jpg"></td></tr>
</table>
<p>
Also, Shamus Young has <a target=shamus href="http://www.shamusyoung.com/twentysidedtale/?p=15904">
run into some problems</a> using Qt as his GUI toolkit, and I'm trying to convince him to switch
to my GUI.  Which of course does not work yet.  So I'm going to have to make some extra efforts
in that direction.
<p>
There will be a full post soon with the mini-game (called "Don't Hit Me!") and something on the GUI.

]]></content:encoded>
</item>

<item>
<dc:date>2012-05-03T07:00:00-07:00</dc:date>
<title>GUI Design Contest Results</title>
<dc:subject>
Some interesting designs have come in.
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/Delay/DesignContest2.html</guid>
<link>http://www.sea-of-memes.com/Delay/DesignContest2.html</link>
<description>
Some interesting designs have come in.
</description>
<content:encoded><![CDATA[

<h2>GUI Design Contest Results</h2>
<p>
The contest did not start well.  I was just getting variations on the
concept that I had supplied.  The staff at 99designs suggested that I had overspecified
what I wanted (I was just trying not to be vague) and told me to simplify my brief.
They also extended the contest for me, free of charge.  Since then, several interesting
variations have come in.
<p>
The best of the initial round was from reader Florian B&#246;sch, shown here:
<p>
<table align=center>
<caption align=bottom>Florian's UI</caption>
<tr><td><img width=768 src="http://www.sea-of-memes.com/Delay/design4.jpg"></td></tr>
</table>
<p>
I'd be happy to use this for UI work, and will try to do a skin for my GUI that
uses this style.  For SeaOfMemes, I wanted something more in the spirit of the 
game.  I asked people to submit concepts, not detailed designs, and suggested
something that looked like a building blueprint.  I like these two designs:
<p>
<table align=center>
<caption align=bottom>Eikonographer's UI</caption>
<tr><td><img width=768 src="http://www.sea-of-memes.com/Delay/design1.jpg"></td></tr>
</table>

<p>
<table align=center>
<caption align=bottom>Liu Design's UI</caption>
<tr><td><img width=768 src="http://www.sea-of-memes.com/Delay/design3.jpg"></td></tr>
</table>
<p>
I've also gotten some other creative designs like this one:
<p>
<table align=center>
<caption align=bottom>mmactor's UI</caption>
<tr><td><img width=768 src="http://www.sea-of-memes.com/Delay/design2.jpg"></td></tr>
</table>

<h2>A Poll</h2>
<p>
I'm still looking at designs and making suggestions to the designers.  What
do you think?  Here's a <a target=poll href="http://polldaddy.com/poll/6194885/">poll.</a>
Please comment on the designs shown.  I still have some time on the contest 
to get what I want.

]]></content:encoded>
</item>

<item>
<dc:date>2012-04-27T15:00:00-07:00</dc:date>
<title>GUI Design Contest</title>
<dc:subject>
I've submitted a GUI design contest to 99designs.com
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/Delay/DesignContest.html</guid>
<link>http://www.sea-of-memes.com/Delay/DesignContest.html</link>
<description>
I've submitted a GUI design contest to 99designs.com
</description>
<content:encoded><![CDATA[

<h2>GUI Design Contest</h2>
<p>
I've been working on my GUI code, and decided to use the graphic design
site <a target=designs href="http://99designs.com">99designs.com</a> to 
find a concept/color scheme for the UI.
<p>
For any of you who are graphic designers and want to take a crack at it,
the contest is 
<a target=contest href="https://99designs.com/icon-button-design/contests/video-game-ui-concept-136446/brief">here.</a>

<h2>Design Brief</h2>
<p>
I am writing a video game and need a concept for the user interface graphics.
I'm not looking for individual icons yet (I'll bid that work out separately),
just an overall look.
<p>
The example I've provided (see "sample-concept.jpg") has some of the
characteristics I'm looking for:
<p>
<ul>
<li>It's translucent, so that players can monitor the game while they are 
using windows/dialogs, etc.<p>

<li>It has a technical/engineering flavor, to match the game.  My attempt was
inspired by blueprints.  It has a blue color scheme and uses an italic
sans-serif font.<p>

<li>I want something fairly minimal and clean, since the user's attention
should be given to the game, not the UI.<p>
</ul>
<p>
On the other hand, I'm a programmer, not an artist, and I'm not attached
to the particulars of the sample concept.  If you have a completely different 
idea, please submit it.
<p>
I've made both the dialogs and controls 30% transparent. Feel free to try variations 
on this, as long as controls are readable over the sample backgrounds.  The 
video game code can support any texture on the control/dialog background.  
Transparency can vary over the surface if you like.  Textures can be an arbitrary 
R,G,B,A image, in other words.
<p>
Your submissions should be in the form of a PNG file with appropriate
levels of transparency (see "submission.png").  Three sample background 
images are provided.  Your UI concept should be readable over all three.
You will be specifying:
<p>
<ul>
<li>A color scheme.  Specify colors of the dialog background, a disabled 
button, an unpressed ("up") button, a button with the mouse over it 
("hover"), and a pressed ("down") button.  I also need colors for text 
in various uses, the background and text color of a menu item, etc.<p>

<li>Background textures.  As mentioned, the dialog and control backgrounds
can be any texture with any amount of transparency.<p>

<li>A font.  Please use either standard Web fonts or open source fonts
(give a source URL.)  My code only supports TrueType fonts.  I'm using 
a font called "Sansation" in the example.  Download from 
<a href="http://www.fontsquirrel.com/fonts/Sansation">www.fontsquirrel.com/fonts/Sansation</a>
if you are interested in using it (not required.)<p>

<li>Button/icon styles.  I don't expect a finished icon design, but please
indicate if button graphics would be heavy or light, italic, curved, etc.
and the color scheme.  A rough sketch on the submission image is sufficient.<p>
</ul>
<p>
In addition to the design fee, I will be happy to credit the designer and
give a link to your website in my documentation.

<p>
<h3>Sample-concept.jpg</h3>
<img width=768 src="http://www.sea-of-memes.com/Delay/sample-concept.jpg">

<h3>Submission.png</h3>
<img width=768 src="http://www.sea-of-memes.com/Delay/submission.png">

<h3>Background1.jpg</h3>
<img width=768 src="http://www.sea-of-memes.com/Delay/background1.jpg">

<h3>Background2.jpg</h3>
<img width=768 src="http://www.sea-of-memes.com/Delay/background2.jpg">

<h3>Background3.jpg</h3>
<img width=768 src="http://www.sea-of-memes.com/Delay/background3.jpg">

]]></content:encoded>
</item>

<item>
<dc:date>2012-04-19T09:24:00-07:00</dc:date>
<title>Sleepless in Sacramento</title>
<dc:subject>
My brain has blue-screened.  Sorry.
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/Delay/Sleepless.html</guid>
<link>http://www.sea-of-memes.com/Delay/Sleepless.html</link>
<description>
My brain has blue-screened.  Sorry.
</description>
<content:encoded><![CDATA[

<h2>Sleepless in Sacramento</h2>
<p>
In the last part, I described keeping the landscape as some kind of Octree, and was
trying to figure out the shape of a leaf node.  I needed something that would do
heightmaps, but also let me break things into cubes, and dig holes in the landscape.
I was imagining some kind of discrete shape, like a collection of tetrahedra.
<p>
<table align=right>
<caption align=bottom>Fig 1: Hermite data</caption>
<tr><td><img src="http://www.sea-of-memes.com/Delay/hermite.gif"></td></tr>
</table>
Reader Scott Richmond linked three papers on variations of "Dual Contouring", which
I think will be the right answer.  The leaf cubes will contain up to 12 points,
the intersection of the desired surface with the edges of the cube.  Each point 
also has a normal associated with it, indicating the direction of the surface.
In two dimensions, it looks like Figure 1.
<p>
In the papers, this is called "Hermite" data, and the algorithms use a "quadratic error function"
which is minimized to place each polygon point during a modified "Marching Cubes"
algorithm.  I am still working through the papers to figure out what this all means!
<p>
The surface intersections and normals are easy to generate from the procedural
heightmap-based landscape.  I'm not sure exactly how I'll be manipulating those
when the player digs holes.  And I'm not sure when I recompute the polygonal
form of the surface.  I don't know how expensive that will get, and whether
I can do it in sections (so they can be cached), or if I have to redo the entire
landscape on each change.  Since the input cubes change whenever you move
(cubes get smaller as you move nearer) or when you dig, this needs to be fast.
<p>
<h2>Sleepless</h2>

I'm not sure when I'll get this working.  My health has really been acting up for the last 
month or two.  I haven't had a decent night's sleep in weeks.  I've been staring at 
these papers for the last week, but I just don't have enough brain cells working 
at this point to figure out the algorithm.
<p>
While I wait for a doctor's appointment and the inevitable tests, I've decided to work on 
some odds and ends like my old GUI and adding features to Crafty.  That can be done in 
small bursts and don't require any math, which my tired brain just isn't capable of right now.
I'll post again when I get something working.



]]></content:encoded>
</item>



<item>
<dc:date>2012-04-12T06:30:00-07:00</dc:date>
<title>Part 54: Stuck</title>
<dc:subject>
Still trying to get modifiable landscape to work. 
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/LetsCode54/LetsCode54.html</guid>
<link>http://www.sea-of-memes.com/LetsCode54/LetsCode54.html</link>
<description>
Still trying to get modifiable landscape to work. 
</description>
<content:encoded><![CDATA[

<h2>Part 54: Stuck</h2>
<p>
<table align=center>
<caption align=bottom>Fig 1: Heightmap-based landscape</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/heightmap-landscape.jpg"></td></tr>
</table>
<p>
Since the beginning of the project, I've been talking about putting Minecraft-style
structures made of cubes on a polygonal landscape.  I just can't render a large 
world with distant views if it's all made of cubes.  They take too long to render,
and are too hard to summarize in the distance.  Also, I just like the look of
a polygonal landscape.  Figure 1 looks much better to me than anything done
with cubes.
<p>
I've been doing polygonal landscapes with heightmaps.  You have a grid in x and z,
and each point has a height in y.  Each square cell of the grid is drawn with two triangles.
In <a target=part28 href="/LetsCode28/LetsCode28.html">Part 28</a> I showed
how you could vary the resolution of a quad-tree, where each node contained a 32 by 32
heightmap.  By using coarser grids in the distance, the demo can draw a view right
out to the horizon without using too many triangles.
<p>
The problem with heightmaps is they are only vertical.  If you play with Minecraft,
you can see that caves are really important to the look.  On the 
<a target=d20 href="http://www.shamusyoung.com/twentysidedtale/?page_id=14954">TwentyMine</a> server,
there are all kinds of interesting underground structures.  So although my fallback
was to just use heightmaps and let you dig vertically before building, I've wanted a 
better data structure.
<p>
In particular, for my asteroids, I want you to be able to carve them up and make
any structure you like out of them, from a hollow habitat (Figure 2), to some
bizarre nesting of levels and structures at all angles.
<p>
<table align=right>
<caption align=bottom>Fig 2: A hollow asteroid</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/habitat.jpg"></td></tr>
</table>
I've been toying with different kinds of data structure for months now, trying
to find one that would do what I want:
<ul>
<li>It has to handle arbitrary 3D shapes with mountains, caves, holes, etc.<p>

<li>When the player digs through a mountain or shell of an asteroid, I need to 
easily know when he's broken through to the other side.<p>

<li>I need to be able to summarize landscape at lower resolution in the distance.
For example, if you dig out a mountain, ideally I'd like to see some sign of the
holes when you move far away.<p>

<li>The rendering code can quickly extract a list of triangles to draw, and they
should not include too many extra, obscured triangles.<p>

<li>I should be able to do at least what a heightmap would do.<p>

<li>It can't take a ridiculous amount of memory for the kind of landscapes I'm using.<p>
</ul>

<h2>Six-sided height maps</h2>
<table align=right>
<caption align=bottom>Fig 3: Height maps in all directions</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/six-sided.jpg"></td></tr>
</table>
In the asteroid case, the ground might be oriented in any direction, so I decided the
simplest approach was a cube with a height map on each face.  When I needed to switch
directions for a cave, I would just build another level of the tree and have a heightmap
in the correct direction.  In two-dimensions, Figure 3 shows a bunch of heightmaps in
all directions.
<p>
You can start to see the problems even in this illustration.  The data structure does
not enforce anything about the height map values, so they might not meet up at corners,
or the bottom heights might extend until they hit the opposite face, or even the sides.
As you dig, I would continually have to check the intersections with the nearby faces, 
both horizontal and vertical.
<p>
I was also originally thinking each node in the tree is a 32 by 32 by 32 cube with a 
heightmap, but this won't work.  It would only allow you to dig 32 by 32 meter holes
in the landscape!  To have arbitrary shapes, I would have to take the scale down to 
a single cube.  If each cube had a 32 by 32 heightmap on each face, that's too much
memory.
<p>
After more thought, I decided that this all really reduces to an Octree, and the only 
question here is what shape is in the leaf cube.

<h2>Leaf Shapes</h2>
<table align=center>
<caption align=bottom>Fig 4: Larger cubes in the distance</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/distant-cubes.jpg"></td></tr>
</table>
<p>
If you kept only a single bit per leaf cube, you'd have a Minecraft-like world, except
with larger cubes in the distance.  This works and satisfies all my criteria except
that it looks terrible.  It won't do the nice landscape in the distance that a heightmap 
will do.
<p>
<table align=right>
<caption align=bottom>Fig 5: 8-point<br>nodes<br>&nbsp;</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/8-point-node.jpg"></td></tr>
</table>
To implement a heightmap, the leaf cube has to handle a height at all four corners.
To handle my asteroid case, it has to do this in any of the six face directions.  
Last week, I was thinking that I would just implement the leaf cube with 8 points 
that can have arbitrary positions within the cube (Figure 5.)  The leaf shape is drawn just 
as I currently draw cubes -- with two triangles per face.  
<p>
If I set the bottom corners to be at the cube points, and the top corners to follow
the heightmap, I could do everything I currently do with heightmaps.  When digging,
I would need to push the corner points into the cube until they intersected the
opposite face.  At that point, the cube is empty.
<p>
<table align=left>
<caption align=bottom>Fig 6: Clipped<br>8-point<br>nodes</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/clipped-saddle.jpg"></td></tr>
</table>
Unfortunately, since I'm so poor at visualizing things in three dimensions, the 
obvious problem had never occurred to me.  The adjacent points of a heightmap landscape 
are not necessarily within a cube.  In fact, clipped to a cube, you can get some nasty
shapes (Figure 6.)  To avoid this, I would have to constrain the 8 points to be
within the cube, which restricts the shapes the player can build.
<p>
You might think this doesn't matter, and close up, it probably wouldn't matter much.
It would just mean that as you dig, whole cubes disappear when you think there
should still be a sliver.  In the distance though, constraining the surface points 
to fit in a cube means you can't have more than a 50% slope, and the mountains
of Figure 1 are impossible.  It would also be impossible to draw a deep cut
into a more gently sloping mountain.

<h2>Tetrahedrons?</h2>

<table align=right>
<caption align=bottom>Fig 7: Subdividing tetrahedra</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/tetrahedra.jpg"></td></tr>
</table>
If the surface of the heightmap is drawn as two triangles per cell, then my leaf
shape is the union of two tetrahedrons.  I briefly considered redoing the whole
thing with a tree of tetrahedrons, since the landscape shape can definitely be 
broken up that way.  
<p>
Unfortunately, the tree wouldn't have a nice structure
like the Octree.  The tetrahedron would not be split at regular intervals
-- that would just build the landscape out of fixed-sized pyramids instead of
cubes.  Instead, we need to split at arbitrary points along the edges.
<p>
If you imagine a large "universe"-sized tetrahedron, the landscape would be a 
bit of noise at the bottom.  As you subdivided the top level tetrahedron, you would
get all kinds of thin slices, leading to round off errors and probably some
"flimmering" when you drew parts of the shape.
<p>
I also rejected this because I simply can't visualize what is going on.  In the
simple case of Figure 7, where you cut each edge at one point, how many child
tetrahedra are there?  I can't visualize what is happening in the center.
I could probably look it up somewhere, but the fact that
it's not obvious to my defective 3-d reasoning makes me nervous.  This is
not a data structure I want to work with.

<h2>Oriented cubes?</h2>
<p>
<table align=right>
<caption align=bottom>Fig 8: Oriented cubes</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode54/oriented.jpg"></td></tr>
</table>
I have two problems with the leaf shape.  One is that I'm insisting on doing
everything from all six sides of the cube.  That makes even a simple shape much
more complex.  I could solve this by orienting the cubes, so that the shape,
whatever it is, always faces "up".
<p>
Figure 8 shows the 2D version.  Independent of rotations, there are two cases.
The box is either on the axis or on the diagonal.  Picture a little heightmap
or whatever inside each box, where "up" is in the direction of the arrow.
<p>
In 3D, there would be three cases -- the cube imbedded in a surface, with one 
face exposed, the corner with two faces exposed, and the corner with three faces 
exposed.  I could define "up" in the corner cases as pointing along a diagonal
of the cube.
<p>
Doing the cubes this way means checking that when the player deletes a cube, I also
delete neighbors to make sure no cube has opposite sides exposed.  That's
manageable.
<p>
The other problem is the shape itself.  I could just go ahead and use
four heights making two triangles, and clip them to the cube.  A stack 
of these with a steep slope is going to draw all the clipped shapes,
and there is some round-off error to worry about, but it would work.
<p>
When you are digging, you might touch the middle of a sequence of these
cubes, all with identical slopes.  I'm not sure what happens to the 
middle cube in that situation, or how I adapt the neighbors.
<p>
I'd like to find some more natural shape to put in the leaf cubes,
so that the landscape is built out of these shapes, and digging just
removes some of the shapes.  Perhaps there's
a better way to do the whole thing!  I'm open to suggestions.


]]></content:encoded>
</item>


<item>
<dc:date>2012-04-04T00:22:00-07:00</dc:date>
<title>Part 53: Storing World Data</title>
<dc:subject>
Feels like reinventing the wheel, but here's my solution.
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/LetsCode53/LetsCode53.html</guid>
<link>http://www.sea-of-memes.com/LetsCode53/LetsCode53.html</link>
<description>
Feels like reinventing the wheel, but here's my solution.
</description>
<content:encoded><![CDATA[
<h2>Part 53: Storing World Data</h2>
<p>
Minecraft stores its world data in a collection of files.  Over the multiple versions
of the program, the structure seems to have turned into a bit of a mess.  The <tt>region</tt>
directory contains two versions of everything -- the old <tt>mcr</tt> files and the new
<tt>mca</tt> files.  I think the DB is using both ZLib compression (for regions), and
GZip file format (for the <tt>level.dat</tt> file.)  The compressed formats don't just compress
the raw data, but compress the "NBT" file format which originally stored the data in 
individual files.
<p>
Needless to say, I don't want anything like this to happen to my database format!  I also
have the problem that in Crafty at least, game developers are going to want to add their
own state information.  So I need a format that will support growth and extensions by 
other programmers.
<p>
Back in the early parts of this project, I had a version of Crafty with a file format 
of its own.  I was storing all the 32 by 32 by 32 chunks of landscape in individual XML 
files.  The sample world had several thousand of these chunks.  I was relying on the Octree
format to provide for some compression, but not doing much otherwise.
<p>
When Notch switched to the region format, it was claimed that storing multiple
individual chunks in a single large region file improved performance.  I have no
reason to doubt this, but it is irritating.  Storing data on disk is the job
of the operating system.  Redoing this in your own layer seems like 
reinventing the wheel.  On the other hand, I could clearly see that copying
these thousands of files, between my machines or to make backups, was extremely
slow.  The file system just isn't optimized around this kind of use.
<p>
So I need a format that can store large amounts of data, be used for 
individual files (for things like avatars) or huge collections (for regions),
which can grow to hold new information, that isn't locked down to the
particulars of the world (like chunk sizes), and that can be upgraded without 
breaking anything in old code.
<p>
It was tempting to do something XML-ish, with nested tags and so on, since
that's the direction of file formats out on the net.  On the other hand,
I didn't want a complex format or interface, since there would inevitably
be problems with it.  
<p>
I also need something with decent performance, 
which means binary data and indexes which point directly to objects in the
file, not text which you parse.  I finally decided to go the other direction, 
and make it all brutally simple.

<h2>The Interface</h2>
<p>
There is a format signature at the very beginning of the file, which can
be read without knowing anything else about the file format.
This means that if a better implementation comes along, I can create a new
format, signaled by a new signature, and completely change the structure of 
the files without changing this interface.
<p>
The interface supports a table of objects, each of which is an unformatted
byte array.  Each object is identified by a key, which is a variable-length
string, with some reasonably large maximum length (say 512 bytes.)  In 
addition, each object has a 64-bit version id.  
<p>
This version represents
changes to the object, not to the format of an object.  So for example, 
the first version of a landscape before you modify it is version 0.  Then
when you add a block, that's version 1.  Add another block, that's version 2,
etc.  
<p>
This will be used in the multiplayer game world.  Your 
local database will be a cache for objects you've seen.  When you enter
the world, the client will display the versions it has on disk.  At the
same time, it is requesting the most recent versions from the server,
with queries of the form "get chunk at 32, 64, 32.  I have version 1234".
If the server has a more recent version, it can send it.  Otherwise,
the client uses what it has.  
<p>
Here is the complete interface of the <tt>ObjectStore</tt> class.
I implemented this in C++, but I'll 'pseudocode' it for non-C programmers.
<p>
<table bgcolor="#E0E0E0" width=80% align=center>

<tr><td colspan=2><b>getFormat</b>(string <b>fileName</b>) returns string <b>formatSig</b></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Return the format signature on a file.  The signature is the first line of a file,
terminated by a newline.  No other data is required for this method.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>create</b>(string <b>fileName</b>, string <b>formatSig</b>)</td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Create a new object DB, with the filename and signature.  It's an error
if the file already exists.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>open</b>(string <b>fileName</b>, string <b>formatSig</b>)
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Open an existing object DB.  It's an error if the format signature does not match.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>close</b>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Close the DB.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>writeObject</b>(string <b>key</b>, int64 <b>version</b>, int32 <b>length</b>, byte array <b>data</b>)
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Writes the new version of an object identified by <b>key</b>.  If an old version exists, it is deleted.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>readObject</b>(string <b>key</b>) returns int64 <b>version</b>, int32 <b>length</b>, byte array <b>data</b>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Read the object identifed by <b>key</b>, returning the data and version.  If the object does not exist,
a null is returned.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>deleteObject</b>(string <b>key</b>)
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Delete the object identified by <b>key</b>.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>indexStartPosition</b>() returns an int32 <b>position</b>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Start reading the index.  A position of -1 indicates read complete.
</td></tr>

<tr><td colspan=2>&nbsp;</tr></tr>

<tr><td colspan=2><b>indexNextKey</b>(int32 <b>position</b>) returns string <b>key</b>, int64 <b>version</b>, 
int32 <b>position</b>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td valign=top>
Read the next entry in the index.  The key and version of an object are returned.  A position of -1
indicates read complete.
</td></tr>

</table>
<p>
As I said, it's simple.  The structure is all in the keys.  For example, the Minecraft-style chunks
have a major code, minor code for each brick (2 bytes total), and two lighting codes (4 bits each).  You could implement
this with keys like:
<p>
<ul>
<li>"block/32,64,32/bricks" for the brick codes, writing 32 by 32 by 32 by 2 bytes of brick type data.<p>
<li>"block/32,64,32/lights" for the light codes, writing 32 by 32 by 32 by 8 bits of light intensity data.
</ul>
<p>
Other likely objects would include position of the players, animals, etc.  No structure is imposed
on the key names, but the programmer can clearly create a complex structure with this interface.

<p>
As the game code evolves, and the programmer wants to keep compatibility, he creates new key names.
A version of the brick data with more brick types might be named "block/32,64,32/bigbricks".  To do
the conversion, the program reads the index for all objects ending in "/bricks" and upgrades them
to "/bigbricks" blocks, deleting the old versions.
<p>
New data is added to the world by generating new keys.  If biomes are introduced, a new key
"block/32,64,32/biome" can be used.  In old databases where it is not present, a new version
can be generated.
<p>
Two restrictions on the DB can be seen immediately:
<ul>
<li>There should be few enough objects per DB to conveniently scan through them all, at load 
time, or on demand.  DB files do not contain millions of objects.<p>

<li>Each object is small enough to return as a single byte array.  There is no method for 
reading subareas of an object.  I am keeping the data compressed with ZLib, so partial reads 
would be a nuisance to implement. Minecraft blocks are on the order of 32K bytes.  
</ul>
<p>
In use, a single DB could be one object (such as an avatar definition), all the attributes
of a single chunk, or a region of chunks.  It's left to the programmer to 
decide what granularity to use.


<h2>The Implementation</h2>
<p>
My first thought was that I needed to read and write objects as continuous ranges of bytes
in the file, to get the best performance.  I would then have to track free space
and do some kind of first-fit or best-fit algorithm to allocate ranges for objects.  I don't
want an index at the start which would grow and require objects to be moved, so the index 
could be put at the end.  You will be rewriting the index whenever you write new data anyway.
<p>
Several things put me off doing this kind of implementation:
<p>
<ul>
<li>The data is going through ZLib for compression and decompression.  That's liable
to be the bottleneck, not disk I/O.<p>

<li>Most objects will compress to a block or two, making I/O even less of an issue.<p>

<li>Although performance of reads could be important, writes are done in the background, 
and are not performance critical.<p>

<li>Even if you use continuous ranges of a file, the OS is not going to allocate continuous
blocks on disk.<p>

<li>The objects will slowly grow as the game is used, making fragmentation a problem.  You
are always going to need a slightly bigger slot than the object previously required.<p>

<li>When the program eventually crashes, the code can die in the middle of an object write,
corrupting the DB.  I need to be able to reconstruct the objects despite partial writes.
</ul>
<p>
I decided to just do something straightforward, and use a linked list of blocks, even though
that guarantees I'll never read more than one block at a time.  If this turns out to be 
an issue, I can revisit the design.  File systems seem to cache an awful lot of file data 
in memory nowadays, so I'm not sure I'll even notice.
<p>
My impulse was to put a block header at the start of each block, but I didn't do that here.
I wanted the very first bytes of the file to be the format signature, not the block zero header,
so I put the header at the end of each (4K) block.  The header contains the complete key of 
the object, version number, a block sequence number, and the next block in the chain.  The 
last block has a next-block value of -1.
<p>
When I write an object, the code writes the new version then deletes the old
version.  A new index is written when there's nothing else to do.  In case of a crash, 
odds are that at least one complete version of the object will be present.  Since all 
blocks are tagged with the key, version and block sequence numbers, I can 
sequentially read the DB and rebuild the index if it has been corrupted.
<p>
The index is just another object, with two exceptions.  First, it always starts in block zero.
Second, when it is rewritten, it reuses the existing chain of index blocks, instead of allocating
new ones.  Since I am reusing block zero, it doesn't make sense to allocate new blocks for
the rest of the index on a rewrite.
<p>
The free block list is written after the index, and updated when the index is.  In addition,
blocks are zero'd when they are freed (when an object is deleted.)  
This is unnecessary,
since the free list could be computed from all the blocks not used in objects, if the DB had
to be reconstructed.  
<p>
It's a bit of extra work, rewriting all the deleted blocks, so if it turns
out to be performance critical, I might stop doing it.  But as I noted above, writes are done
in the background and are not going to be performance critical.  For debugging, I wanted
the deleted blocks to be empty.


<h2>Current Status</h2>
<p>
I've implemented a first pass on this, and done a trivial amount of testing.  Next I'll probably
add some code to McrView to export into this format.  Crafty and SeaOfMemes will import these files 
and use them to store modified world data.
<p>
I'm still working on the new code for modifiable landscape.  Hopefully, that will be done for the 
next part.
<p>
<table align=center>
<caption align=bottom>Terrain</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode53/terrain.jpg"></td></tr>
</table>


]]></content:encoded>
</item>


<item>
<dc:date>2012-03-27T11:00:00-07:00</dc:date>
<title>Part 52: Scripting Languages</title>
<dc:subject>
Another decision I'll have to make one of these days. 
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/LetsCode52/LetsCode52.html</guid>
<link>http://www.sea-of-memes.com/LetsCode52/LetsCode52.html</link>
<description>
Another decision I'll have to make one of these days. 
</description>
<content:encoded><![CDATA[

<h2>Part 52: Scripting Languages</h2>
<p>
I'm currently working on two separate topics -- a new version of Crafty, and a new landscape
algorithm.  I've been switching back and forth and neither is ready for release.  So here's
another filler part, on scripting languages.

<p>
<table align=center>
<caption align=bottom>Rube Goldberg: Didn't he design C++?</caption>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode52/rube-goldberg.jpg"></td></tr>
</table>
<p>
The goal of Crafty is to be a framework for development of block-world games.  I could just
let people program their games in C++ and call into the framework.  However, there will be plenty 
of casual game designers who would like something less formidable than C++.  
A scripting language would be nice, and there are several open-source alternatives.
<p>
Here are my criteria:
<p>
<ul>
<li><b>Familiarity.</b>  I want a language that a reasonable number of programmers will know,
that's well documented, and has a decent-sized community online.  I don't 
want to be in the business of writing tutorials or debugging scripts for people.
<p>
<li><b>Integration.</b>  I need to integrate the scripting language into the framework.  I need
to manage its use of resources (trivial loops in the script should not freeze the game), and
easily call into my framework from the scripts.
<p>
<li><b>Development Environment.</b>  For a first version, it would be acceptable to have
a separate tool that compiles scripts.  When an error occurs (or the script "prints"
an output), the message could appear on an in-game console window.
<p>
As games get more complex, I don't think this will be enough.  Ideally, I'd like an
in-game development environment, where you could create your castle, create an instance
of a dragon, open a window and attach a script to the "someone approaches" event handler
for the dragon, and then debug the script.  This is a significant piece of work with
most of the languages I've looked at.
</ul>

<h2>Some Open Source Languages</h2>
<p>
I've been looking around the net for various open source language implementations.  Here's what
I have so far:

<h3>Lua</h3>
<p>
<a target=lua href="http://www.lua.org/"><b>Lua</b></a> is a small interpreter which claims to 
be "the leading scripting language in games", and to have been used in World of Warcraft.  I haven't
played with it at all yet, but it sounds like it would do the job.
Code looks like this:
<p>
<pre>
 -- add all elements of array `a'
function add (a)
  local sum = 0
  for i,v in ipairs(a) do
    sum = sum + v
  end
  return sum
end
</pre>
<p>
Skimming the documentation, it actually has more language concepts than I would have put
into a scripting language.  The biggest downside is that I would have to learn it. :-)

<h3>JavaScript</h3>
<p>
The <a target=js href="http://code.google.com/p/v8/">Google V8 JavaScript</a> interpreter is
open source and has a just-in-time compiler for Intel machines.  This is probably the best 
known of the languages I could pick, given the number of casual web programmers out there.  
Code looks like this:
<pre>
var i;
for (i = 0; i < 5; i++)
{
  document.write("The number is " + i);
  document.write("&lt;br/&gt;");
}
</pre>
<p>
I have a certain amount of prejudice against this language.  I implemented a compiler for
it as part of a project back in 1997.  This was before the formal spec was available, and
the language was a bit different under each web browser.  I got very frustrated by the
sloppiness of most of the implementations.  I think at one point I had a test case that
crashed every browser I tried!  I also think the language itself is a bit loose.
<p>
Since this is a JIT interpreter (compiles to machine language), I guess I would be stuck 
if I tried to port the framework to the iPad, but I'm not sure Apple is allowing 
interpreters inside apps anyway.

<h3>Smalltalk</h3>
<p>
The last time I used Smalltalk was in 1992, at a company doing pen-based computers.  
There's an open source implementation called <a target=squeak href="http://www.squeak.org/">Squeak.</a>
One advantage is that I think Smalltalk systems normally
implement an IDE in Smalltalk as part of the language.  So I would get "in-world" development tools, 
including a debugger, with the language.  Code looks like this:
<p>
<pre>
n := 1.
[ n < 1000 ] whileTrue: [ n := n*2 ].
</pre>
<p>
I liked the language for the generality of it, and the small number of concepts.  Although 
it was intended to be easy to learn, I'm not sure that it really is.  Some of the block 
and class concepts can get a bit subtle.  Perhaps it's just coming from a C++ background 
that made it all feel strange.
<p>
Although the language is very well known to computer science students, I'm not sure many 
casual web programmers have even heard of it, let alone know how to write it.

<h3>Java</h3>
<p>
Does anyone know what the situation is with an open source Java implementation?  Google pulls up
some projects, but also comments about Oracle suing Google over Android.  Apparently there are
patents, but I'm not sure what they cover (language, or some VM internals?)  Code looks like this:
<p>
<pre>
int sum = 0;
for (int i = 0; i < 5; i++)
{
  sum += i; 
}
</pre>
<p>
If you include all the standard class libraries, Java would make an excessively huge scripting 
language.  I'm also not sure how hard it would be to integrate into the rest of my framework.
I need to call from C++ into Java, then back out to the framework.  Calling the compiler and
a debugger from in-world also seems like a challenge.

<h3>Python</h3>
<p>
<a target=python href="http://www.python.org/">Python</a> is another popular programming language
that I don't know.  Code looks like: 
<p>
<pre>
def fib(n):    # write Fibonacci series up to n
    """Print a Fibonacci series up to n."""
    a, b = 0, 1
    while a < n:
        print(a, end=' ')
        a, b = b, a+b
    print()
</pre>
<p>
Personally, I hate using indent level to define blocks.  It looks really unnatural to me
after 40 years of languages with block delimiters.  I wouldn't let that stop me if this
was my choice of language though.
<p>
More of a problem is the language itself.  I'm a minimalist when it comes to languages,
and paging through the tutorials, Python seems huge.  There are a lot of different concepts, 
a lot of syntax, and a huge standard library.  I'm not thrilled.

<h3>My Own Java</h3>
<p>
On various projects in the past, I've written compilers/interpreters for Pascal, JavaScript
and Java.  I can't really justify designing and implementing a "real" programming language 
for this project, even though I'd like to. :-)
<p>
However, I have my own implementation of Java, written as part of an earlier 
attempt at this project in 2005.  It doesn't handle 100% of the syntax (and there have been 
changes to Java since then), almost no standard classes are implemented, and it's slow,
but it would do as a scripting language.
<p>
The language is well documented and many programmers know it.  Plus the expression syntax
of Java is almost identical to both C++ and JavaScript.  On the other hand, a restricted 
implementation of Java that doesn't have most of the class library might just be annoying
to Java programmers.
<p>
I mostly want scripts for simple things like event handlers on creatures ("something is
near you, so attack it.")  For some of the languages above, I'd have to write (or at least
integrate) some kind of editor and debugger into the world anyway.  Working with my own
code could save me a lot of time.

<h2>A Poll</h2>
<p>
As I see it now, Lua or my own Java will be the easiest to integrate into the framework.
V8 JavaScript might not be too bad, and I have no idea about Python.  Integrating a
real Java into the framework looks hard, but I don't even know which codebase I'd be
using for a real Java VM.  If someone knows of a Java being used as a scripting language,
let me know.
<p>
Both real Java and Python strike me as bigger pieces of code than I really want to deal
with at this point, but I could still be convinced.  Smalltalk is the only choice that
will give me an in-game development environment out of the box.  All the other choices
require me to hook in debuggers and my own class editors, etc.
<p>
Here's a <a href="http://polldaddy.com/poll/6077099/">poll</a>.  Scripting is not something
I will get to anytime soon, but I'd like to know what you think.  Choose all languages
you think are acceptable.  Please leave comments if you want to argue for your choice,
or know answers to any of my questions!


]]></content:encoded>
</item>

<item>
<dc:date>2012-03-20T18:30:00-07:00</dc:date>
<title>Part 51: Internationalization</title>
<dc:subject>
Esperanto is the future!
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/LetsCode51/LetsCode51.html</guid>
<link>http://www.sea-of-memes.com/LetsCode51/LetsCode51.html</link>
<description>
Esperanto is the future!
</description>
<content:encoded><![CDATA[

<h2>Part 51: Internationalization</h2>
<p>
The demos and source on the <a target=downloads href="http://www.sea-of-memes.com/downloads.html">download page</a> 
have been updated, along with the GitHub projects.  There are a few minor bug fixes, but 
no new function.  The important change is I brought the OpenGL 2.1 code up to date.  If 
you had troubles running the demos at all on your machine (especially Mac Leopard users), 
try again.  The SaucerMovie demo still doesn't work under Leopard (it does under Lion).
I'll look at it later.
<p>
My current goal is to get all my dead code cleaned up and released as demos.
To that end, I've been working on a new version of Crafty, trying to integrate in some 
of the features that were in previous parts but never released.  That's not done yet 
though, so here's a post about the endlessly frustrating topic of internationalization.
<p>
In retrospect, this was a stupid goal to take on at this point in the project.  I have 
pieces of code in various states of unfinished lying all over the place.  The last thing 
I needed was another piece of code to work on.  I hope it pays off in the end.

<h2>A False Start</h2>
<p>
I wanted the framework to use Unicode -- internally when managing strings, for text 
typed by the user in input controls, text displayed on the screen, error messages and 
in the various option and other input files.  Someone working in a language other
than English should definitely be able to use the demos, and work on the code.
<p>
Fortunately, Windows, Linux and Mac all support 
<a target=wiki href="http://en.wikipedia.org/wiki/Utf-8">UTF-8</a> encoded files.  
This is an extension of standard ASCII that allows 32-bit Unicode characters to be
specified with multi-byte sequences.  If you only use ASCII characters, the file
is straight ASCII.  If you use Unicode, the non-English characters are signalled
with escape sequences.  
<p>
Even better, Visual C++ under Windows, GEdit under Ubuntu Linux, 
and XCode on the Mac all allow you to use Unicode characters in source code,
for both comments and variable names. 
<p>
That's the good news.
<p>
Unfortunately, the shader compilers don't
seem to allow UTF-8 variable names, which must be a nuisance for non-English speaking
programmers.  I suppose I could do some translation to get around this when I load
the shaders in my framework.
<p>
I develop everything under Windows, then port it to Linux, and then to Mac OS.
Under Windows, they clearly want you to switch from 1-byte ASCII to wide characters 
and do everything that way.  The Visual C++ environment defaults to the Unicode
character set, and that option makes all the system calls take wide strings.
So I started to convert my code to use wide strings everywhere.
<p>
The nice part of doing the conversion that way is that very little code changes.
If you were referencing <tt>str[i]</tt> before to get a letter of the string, you can 
still do that.  You just have to change every string you use from normal to wide
characters, and make sure you assign everything to the correct types.  The only problems
I ran into were the few cases where I assume a character is a single byte.  This 
happens when I use memory moves instead of string copy operations, or allocate memory 
in bytes instead of characters.  There were only a few places like that in the code, 
so it all went smoothly.
<p>
OpenGL takes strings in a few places, and won't take wide strings, so those all had
to be converted, which is a nuisance.  Files in UTF-8 have to be converted to wide 
characters on input, and wide strings have to be converted to UTF-8 on output, but 
Windows actually has options on file I/O to do all this for you.  I had the demos
running again in a few days.
<p>
Then I started converting it for Linux and Mac, and realized this was all wrong.
I really hadn't done my homework before I started.

<h2>Systems Programmers and Their Little Jokes</h2>
<p>
The first false note came when I noticed that Unicode is a 32 bit standard,
and Windows wide characters are only 16 bits.  Under Linux and Mac, wide
characters are 32 bits.  So I could have a situation where a Linux chat
program generated a Unicode character that the Windows version could not read.
<p>
The Unicode documentation calls the 16-bit tables the "Basic Multilingual Plane",
and suggests that only rare characters would fall outside that range.  On the
other hand, Wikipedia states that there are Chinese dictionaries with 100,000
characters, which would not fit in 16 bits.  I have no idea how many of these
are used in practice, or how many national variations there are.  16 bits 
suddenly seemed a bit cramped.
<p>
Things got more interesting when I played with the three compilers.  On Windows,
if you write a Unicode string "sigma(&#963;)", the UTF-8 source file will hold the
sigma character, but Visual C++ will complain it's an invalid string.  Under Linux,
it will compile to a UTF-8 string, with two bytes for the sigma character.
The same on the Mac.
<p>
If you specify a wide string, L"sigma(&#963;)", Visual C++ now likes it, and produces
16-bit characters for the entire string.  Linux gcc also likes it, and produces
32-bit characters.  Mac XCode likes the string, but seems to produce UTF-8 characters
padded into a 32-bit frame.  This is so stupid and useless I had to check it twice.
<p>
All three systems have wide versions of the simple string routines like <tt>strlen</tt>, 
which takes the length of a string. I think I could have found wide variations of all 
the C library routines I use.  Text files would have had to be handled differently, 
since <tt>_wfopen</tt> on Windows takes a wide string for a file name, and <tt>fopen</tt> 
on Linux/Mac wants a UTF-8 string.  Windows also wants to write a "Byte Order Mark"
at the head of text files, which Linux and Mac do not.
<p>
I was dithering over whether to use the <tt>wchar_t</tt> type, which is 16 bits on
Windows and 32 bits everywhere else, or just use UTF-8 strings on all three platforms.
UTF-8 seemed better supported in file form, but some of the pages I ran across on
the net made it sound like 32-bit characters in your code was the "real" way to do
internationalization.  What finally decided me was the issue of "combining characters."

<h2>Combining Characters</h2>
<p>
Despite having 32 bits for characters, Unicode does not define every possible 
character.  You can still combine accent marks, subscripts and superscripts, 
bars and arrows and underscores (as in mathematical notation) with other characters.
This combined character takes a single position when drawing the string, or
when moving the cursor in an input field.
<p>
That means that even if I used 32-bit characters internally, I still would not
have one code per "letter" in the string.  A single letter would have to be 
represented as a list of glyphs, all drawn on top of one another.  
<p>
If I can't loop through a string with <tt>str[i]</tt>, I don't see the point of 
using wide characters.  Grumbling, I recoded my framework to use UTF-8 everywhere, 
and added methods to my <tt>mgString</tt> class to iterate through multi-byte 
characters, returning all the codes that make up a single "letter" in the string.  
I actually had to convert the framework <i>back</i> to single-byte characters, since 
I had been doing work on all the apps after the first conversion.  Sigh.

<h2>But Wait, There's More!</h2>
<p>
Some characters
like "&#233;" exist both as single characters in Unicode, and as combining sequences
(the accent plus the "e".)  On input, you'd see the sequence of two characters.
You'd have to know that these can be combined and you have to do the conversion 
by looking the string up in a table somewhere.  I would need to find this list
in some digital form (not a document) that I can convert into a hash table for 
my string code.
<p>
When you combine characters, you have to normalize the order, so that "accent+char"
is equal to "char+accent", even for the combinations that are not represented
as single codes.  There's also a sort order for strings, which is different
for each language.  And rules for converting to lowercase, which I do on things
like options, so that they are not case sensitive.
<p>
Implementing all this is a project in itself, but it's been done.  I downloaded the 
<a target=icu href="http://site.icu-project.org/">International Components for Unicode (ICU)</a>
library which supposedly does everything.  I thought of making this one of the libraries
in my project, but it's huge.  I haven't decided what to do.  I might still incorporate
it as a DLL, or just use it to generate some tables for me to include in my code.
<p>
That's not the end of the work though.  In addition to handling combining characters, 
sorting, etc., I have the problem of input methods.  I can take non-English keys and 
combine them with the right tables.  I can also take numeric codes for Unicode 
characters if you only need an occasional character.
<p>
With a bit more work, I could have pop-up dialogs you can pick characters from, equivalent
to the keymap applications on Windows, Linux and Mac.  I could allow cut and paste
from those apps, but in a full-screen game, that would be a nuisance. 
<p>
For the Asian languages which don't have every character on a key, I would need some
kind of input support.  YouTube pulls up videos that show people typing phonetic 
sequences and then picking from a choice of characters.  I have no way to write that
code, and I don't know where to find it.

<p>
In addition to input, I also have output problems.  I'm not sure where to draw
accent marks and other combined characters when there are multiple characters in 
a cell.  I don't know if there's even enough information to do this with FreeType.

<h2>Error Messages</h2>
<p>
UI dialogs and help text can be translated into different languages.  With a language
option in the code, I could display the correct version without any trouble.  Error
messages are a special case however.  They have variable information.
<p>
In English, I want to say something like "Option 'textFont' cannot be 'Comic Sans'."  
In a different language, the two variables here ('textFont' and 'Comic Sans') could
be presented in a different order.  To handle this case, I defined a little XML
file that holds all my error messages.  An entry looks like:
<pre>
&lt;errorMsg id="xmlNoOpenTag">
  &lt;var name="filename"/>, 
  line &lt;var name="line"/>, 
  col &lt;var name="col"/>: 
  Closing tag "&lt;var name="tagName"/>", 
  open tag is "&lt;var name="topTag"/>".
&lt;/errorMsg>
</pre>
<p>
This would result in a message like: 
<pre>
options.xml, line 22, col 2: Closing tag "opt", open tag is "options".
</pre>
A different language version of the error message would just change the text, and possibly
the order of the <tt>&lt;var></tt> tags in the message xml file.
<p>
In my code, where I used to just throw an exception with the English-language
error message, now I throw an ErrorMsg object with the <tt>"xmlNoOpenTag"</tt>
message code, and the variables listed as arguments.  This is looked up in the
error table and formatted for the user.

<h2>Still To Do</h2>
<p>
The current version of the framework has some UTF-8 support, but there's a lot
more to do:
<ul>
<li>Recognize combining character sequences, normalize them and convert the
ones with single-code equivalents.<p>
<li>Draw combined characters correctly.<p>
<li>Add a numeric Unicode input method.  Annoyingly, there are at least three conventions
in use on the different systems.<p>
<li>Add some kind of pop-up character palette.<p>
<li>Add input helpers for Asian languages, if I can find library code to do this.
</ul>
<p>
This is not next on my list (I'm sick of it!) but I would like to do it eventually.
Some of it is easy.  Unfortunately, I don't even know how much of this is really required.  
I've looked at sources around the net, but I'm not sure how much language support there 
is in most general-purpose apps, or in games.  Do other MMOs (World of Warcraft?)
have Chinese language input helpers?
<p>
Readers, let me know!
<p>
<table align=center>
<caption align=bottom>Esperanto is the future!</caption>
<tr><td><img alt="Engraving The Confusion of Tongues by Gustave Doré (1865)"
src="http://www.sea-of-memes.com/LetsCode51/Confusion_of_Tongues.jpg"></td></tr>
</table>

]]></content:encoded>
</item>


<item>
<dc:date>2012-03-10T10:00:00-08:00</dc:date>
<title>Part 50: Spring Cleaning</title>
<dc:subject>
The demos are all up to date, and the source has been released again.
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/LetsCode50/LetsCode50.html</guid>
<link>http://www.sea-of-memes.com/LetsCode50/LetsCode50.html</link>
<description>
The demos are all up to date, and the source has been released again.
</description>
<content:encoded><![CDATA[

<h2>Part 50: Spring Cleaning</h2>
<p>
Looking at all the pieces of code spread over my disk, and the months of time
which have passed since the last update of the source code on GitHub, I realized 
it's time for some spring cleaning.  I've also added a new 
<a target=downloads href="http://www.sea-of-memes.com/downloads.html">download page</a> to 
the site and changed the <a target=home href="http://www.sea-of-memes.com/">front page.</a>
<p>
You can download all the demos in one big zip here:
<p>
For Windows, download 
<a href="http://www.sea-of-memes.com/LetsCode50/LetsCode_part50_demos_win.zip"
>Part 50 Demos - Windows.</a>
<br>
For Linux, download 
<a href="http://www.sea-of-memes.com/LetsCode50/LetsCode_part50_demos_linux.zip"
>Part 50 Demos - Linux.</a>
<br>
For Mac, download 
<a href="http://www.sea-of-memes.com/LetsCode50/LetsCode_part50_demos_mac.zip"
>Part 50 Demos - Mac.</a>
<p>
You can download all the source code here:
<a href="http://www.sea-of-memes.com/LetsCode50/LetsCode_part50_demos_source.zip"
>Part 50 Demos - Source.</a>
<p>
Or get all the source from GitHub:
<p>
<a href="https://github.com/mgoodfel/mgFramework">https://github.com/mgoodfel/mgFramework</a>
<br>
<a href="https://github.com/mgoodfel/SeaOfMemes">https://github.com/mgoodfel/SeaOfMemes</a>
<br>
<a href="https://github.com/mgoodfel/Crafty">https://github.com/mgoodfel/Crafty</a>
<br>
<a href="https://github.com/mgoodfel/McrView">https://github.com/mgoodfel/McrView</a>

<h2>Changes</h2>
<p>
There are numerous small changes to the framework and demos.  For UI, you can get help on
all the demos with F1.  The demos now start with an arrow cursor and you end the app by
just closing the window.  ESC toggles to a cross cursor which works shooter-style causing
the mouse to turn the eye.
<p>
I've rebuilt the 2D text using the FreeType library, so we now have text on all three
platforms.  Yay!  This may cause some problems:
<ul>
<li>I rely on the operating system to tell me the dots per inch of the display.  This
can be wrong.  If the text is the wrong size, edit the <tt>options.xml</tt> file for
the demo and change the <tt>dpi</tt> option.  Zero is the default and means trust the OS.
Reasonable values are around 100.  Higher numbers will get you larger text.<p>

<li>Each operating system puts the fonts in a different directory, and spells them
differently.  On Windows, we look in <tt>c:\Windows\Fonts</tt> for <tt>georgiaz.ttf</tt>, and on
the Mac we look in <tt>/Library/Fonts</tt> for <tt>Georgia Bold Italic.ttf</tt>.  And so on.
There's now a new file <tt>docs/fonts/fonts.xml</tt> which gives the framework font
names to try.  Rather than hardcode these for each platform, it just looks for all
of them until it finds a font.
<p>
If for some reason, your system is not finding any fonts, the app will put up an error
dialog, or just crash (I don't have error dialogs working on Linux.)  
Send me the <tt>errors.txt</tt> file, or look there yourself
to see if it's looking for the wrong font name on your system, or looking in the 
wrong place.
<p>
<li>I'm not caching any of the character bitmaps produced by FreeType, so text is quite 
a bit slower than it was.  I'll fix that soon.  None of the demos use much text, so you 
shouldn't notice it.
</ul>
<p>
The other big change in the framework is the internationalization code.  I'll write a
separate part on that.  It still needs work.

<h2>Statistics</h2>
<p>
Readers have also asked me to update the statistics on how much code there is in the project.
That's a bit of a problem.  There's a lot of code duplicated in the framework -- between OpenGL 2.1
and OpenGL 3.3, and between the Linux initialization and the Mac initialization, etc.  The demos
have variations on the same code for their UI.  It's a judgement call what to count.
<p>
When I last counted all the code (part 19), I was picking and choosing parts of each platform,
based on how different I thought they were.  I neglected to make a list of which files I counted!
To get comparable counts from then to now, I've redone the Part 19 counts to just include OpenGL 3.3
on Windows, and nothing else.  I've done the same for the Part 50 source.  This is just lines of c/c++
source, with no include files and no shaders.  
<p>
<table>
<tr><th>&nbsp;&nbsp;</th>
<th align=right>Part 19</th>
<th align=right>&nbsp;&nbsp;&nbsp;&nbsp;Part 50</th>

<tr>
<td>Framework lines&nbsp;&nbsp;</td>
<td align=right>7,402</td>
<td align=right>9,405</td>
</tr>

<tr>
<td>Utilities lines</td>
<td align=right>6,738</td>
<td align=right>10,986</td>
</tr>

<tr>
<td>Application lines</td>
<td align=right>8,631</td>
<td align=right>41,421</td>
</tr>

<tr>
<td>Total</td>
<td align=right>22,771</td>
<td align=right>61,812</td>
</tr>

<tr><td colspan=3><hr></td></tr>

<tr>
<td>Coding hours</td>
<td align=right>464.7</td>
<td align=right>1,225.1</td>
</tr>

<tr>
<td>Writeup hours</td>
<td align=right>90.2</td>
<td align=right>243.3</td>
</tr>
</table>
<p>
Counted this way, the 3D framework hasn't grown much.  Some function has actually
moved out of the framework into the "Utilities" category -- all the covering classes
for threads, events and timers moved, for example.  The biggest growth has been
in application code.  
<p>
I've eliminated duplicate code in Crafty, McrView and SeaOfMemes,
as well as duplicate classes in the little framework demos.  I'm also not including 
any of the utilities I've written like the Collada importer, or side projects like 
ray tracing.  So this is an underestimate of the project size at this point.
<p>
I don't plan to update the source totals very often, since it's kind of a nuisance.
I have to combine the source from all the parts of the project, then eliminate any
shared code and any library code.  I'll do it again when I have some kind of significant
milestone.
<p>
Next, let me run through each part of the project and give you the status.


<h2>SeaOfMemes</h2>

<table align=center>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode50/SeaOfMemes-sample.jpg"></td></tr>
</table>
<p>
The demo shows the planet, moon and ring.  You can sort of land on them by approaching
until the range text turns red, then hitting "L".  That should rotate the eye space
until you are in the coordinate system of the object you land on.  It doesn't quite
work right.  Hit "L" again to transition back to space.
<p>
The options file controls the rate of motion of all the system objects.  You can change
the rotation speeds if you like.  The "DayLen" options at the end are in seconds.
Don't use zero.
<p>
There's dead code in the project for asteroids and generation ships, etc.  I'll get 
to work on cleaning that up soon.  For now, this is the same as the Part 41 video.
<p>
To download SeaOfMemes alone, go to <a target=seaofmemes 
href="http://www.sea-of-memes.com/downloads/SeaOfMemes.html">Download SeaOfMemes.</a>
Here's a <a href="http://youtu.be/AcwrhGtA5YI">video.</a>

<h2>Crafty</h2>

<table align=center>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode50/Crafty-sample.jpg"></td></tr>
</table>
<p>
I've thrown out the old Octree-based version and replaced it with the latest
code from McrView.  I'm generating the landscape procedurally and converting
it into cubes as you move.  There's no editing function yet.  That will be
the next item on this part of the project.
<p>
To download Crafty alone, go to <a target=crafty href="http://www.sea-of-memes.com/downloads/Crafty.html">Download Crafty.</a>

<h2>McrView</h2>

<table align=center>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode50/McrView-sample.jpg"></td></tr>
</table>
<p>
There is nothing new in McrView since Part 37.  I'll put putting an export dialog into this next.
<p>
I might also add code to read the location of your avatar from the Minecraft files.
That's kept in a completely different table than the world data,
and so I ignored it.  Some of the worlds I download from the net have the buildings
far away from the (0,0,0) position however, and I can't actually find the good stuff!
<p>
A map view would also be nice.  So would a way to view nether areas.
<p>
Of course, as I was testing this, I happened to fire up the real Minecraft, and noticed
they've changed the file format (again!)  So now I have to add code to handle the new
database.  Sigh.
<p>
To download McrView alone, go to <a target=mcrview href="http://www.sea-of-memes.com/downloads/McrView.html">Download McrView.</a>
Here's a <a href="http://youtu.be/yVm0IxlcwWA">video.</a>

<h2>Framework</h2>
<table align=center>
<tr>
<td><a target=testcube href="http://youtu.be/RnZ0KUuSLEA"><img src="http://www.sea-of-memes.com/LetsCode50/TestCube-small.jpg"><br><center>TestCube</center></a></td>
<td><a target=trees href="http://youtu.be/fsPNjssgAXo"><img src="http://www.sea-of-memes.com/LetsCode50/Trees-small.jpg"><br><center>Trees</center></a></td>
</tr><tr>
<td><a target=landscape href="http://youtu.be/-K8QNpzgKUY"><img src="http://www.sea-of-memes.com/LetsCode50/Landscape-small.jpg"><br><center>Landscape</center></a></td>
<td><a target=saucer href="http://youtu.be/yNOB9Zp-vhw"><img src="http://www.sea-of-memes.com/LetsCode50/SaucerMovie-small.jpg"><br><center>SaucerMovie</center></a></td>
</tr>
</table>
<p>
There are now four framework demos -- TestCube, Trees, Landscape and SaucerMovie.
To download these, go to <a target=framework href="http://www.sea-of-memes.com/downloads/Framework.html">Download Framework.</a>
<p>
That's all for this week.

]]></content:encoded>
</item>


<item>
<dc:date>2012-03-01T05:55:00-08:00</dc:date>
<title>Part 49 Update</title>
<dc:subject>
Now with demos.
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/LetsCode49/LetsCode49Update.html</guid>
<link>http://www.sea-of-memes.com/LetsCode49/LetsCode49Update.html</link>
<description>
Now with demos.
</description>
<content:encoded><![CDATA[
<h2>Part 49 Update</h2>
<p>
Sorry about the two week delay.  I lost another week to health problems, and
I had family visiting for a few days.  I was planning on a more ambitious
Part 50, but it was taking too long.  So here is the Saucer Movie demo for
the three platforms.

<h2>The Linux Port</h2>
<p>
I had used the OpenAL audio package because it ran on all three platforms,
so I expected the port to Linux to be no problem.  And the library did 
compile and link without any issues.  The SaucerMovie program ran, and
I saw all my animation.  But no sound!
<p>
Looking at the diagnostics, OpenAL was reporting that there were no input
or output devices.  When CMake builds the makefiles, it includes the drivers
it thinks are supported on the system.  It turns out that it doesn't add drivers
unless you have the development libraries for them installed (Naturally, since
it can't compile the drivers without the header files.)  Googling, it looked like 
I wanted "Pulse Audio" and perhaps "ASLA".  I installed both of those, rebuilt 
OpenAL and tried again.  
<p>
This time I got sound, and life was great -- for 20 seconds.  Then the program
hung and had to be killed.  Sigh.  The same web page that told me I needed
PulseAudio also complained that it could be unstable with OpenAL and Ubuntu, 
and I thought "not this again!"
<p>
I noticed however that the sound was cutting out at the same point every time
-- right after the saucers stop firing and the "laser" sound is deleted.  So 
I thought perhaps OpenAL wasn't thread safe, or that I was messing up in 
my background thread where I keep feeding buffers of audio to the system.
After hours of walking through that code, I found nothing.
<p>
Finally, I noticed something odd -- the dead saucer was disappearing.  This
is the step <i>after</i> the sounds end, indicating the demo was getting
a bit farther than I had assumed.  I put in some more diagnostics, and sure
enough, it was hanging at the point where it creates the huge fleet of
saucers just offscreen.  I thought perhaps I was creating too many sounds
and overloading something.  That would be a nuisance.
<p>
More tracing revealed that the whole thing was a bug in my code.  When I 
create the fleet of saucers, I just do it brute force.  It has a loop
where it creates a saucer, gives it a random position, then checks to 
make sure that position is not on top of another saucer.  That loop
was never exiting -- as if it could never find a good position for
the new saucer!  The positioning code looks like this:
<p>
<pre>
saucer->m_origin.x = -150+300*rand()/(double) RAND_MAX;
</pre>
I couldn't see anything wrong with this, and it works fine under Windows.
It turns out that on Linux, RAND_MAX is the max integer value (2,147,483,647).
On Windows, it's 32,767.  When I wrote this code, I parenthesized it wrong.
What I have there is equivalent to 
<p>
<pre>
saucer->m_origin.x = -150+ (300*rand()) / (double) RAND_MAX;
</pre>
and when you multiply a max integer value (such as rand can return) by 300,
you can get an overflow.  That meant most of my saucers were on top of
one another, and the loop couldn't find a good position for new ones.
On Windows, this would never happen, because 300*32767 is still in range.
Isn't debugging fun?
<p>
Changing this to
<pre>
saucer->m_origin.x = -150+ 300*(rand() / (double) RAND_MAX);
</pre>
fixed the whole problem, and my SaucerMovie demo worked fine under Linux.
In fact, when I searched my code, this same rand expression was all over the
place, so I replaced them all with a routine to return a random double.

<h2>Installation Issues</h2>
<p>
I was still perplexed about what to do with the OpenAL build though.
I didn't really want to tell people to install two development libraries,
rebuild OpenAL and relink the app to run it!  I didn't see how I could
distribute my own binary version of OpenAL though, since it needs to
be customized to each system it runs on.
<p>
I finally realized that OpenAL was probably an installable package
under Linux, and that I should just link to the dynamic library in
my code, picking up whatever version is present on the system.  And 
sure enough, if you install "libopenal1" under Ubuntu, that all works
fine.  It's kind of a nuisance that it isn't installed by default
though.  Does anyone know what game developers for Linux are supposed
to use?
<p>
On the Mac, OpenAL is their default sound support, and everything worked
right out of the box.  I also did a system update and discovered
I now have OpenGL 3.2 on my MacBook Pro!  Yay!  So you might have nicer,
faster graphics on your system.  The graphics processor in my MacBook Pro
is the same as the one in new models of the Air and Mini.  Hopefully,
OpenGL 3.2 works across the line now.
<p>
So I now have a sound demo on all three platforms.  Let me know if you 
have any problems.  You can play with the options if you want to change
the sounds.  It should play any ogg files you have lying around.
<p>
For Windows, download 
<a href="http://www.sea-of-memes.com/LetsCode49/LetsCode_part49_SaucerMovie_win.zip"
>SaucerMovie Part 49 - Windows.</a>
<p>
For Linux, download 
<a href="http://www.sea-of-memes.com/LetsCode49/LetsCode_part49_SaucerMovie_linux.zip"
>SaucerMovie Part 49 - Linux.</a>
<p>
For Mac, download 
<a href="http://www.sea-of-memes.com/LetsCode49/LetsCode_part49_SaucerMovie_mac.zip"
>SaucerMovie Part 49 - Mac.</a>
<p>
Hit "M" to start the movie animation.

]]></content:encoded>
</item>


<item>
<dc:date>2012-02-17T01:30:00-08:00</dc:date>
<title>Part 49: Sound</title>
<dc:subject>
Beep!  Boop!  It's a video game.
</dc:subject>
<guid isPermaLink="true">http://www.sea-of-memes.com/LetsCode49/LetsCode49.html</guid>
<link>http://www.sea-of-memes.com/LetsCode49/LetsCode49.html</link>
<description>
Beep!  Boop!  It's a video game.
</description>
<content:encoded><![CDATA[

<h2>Part 49: Sound</h2>
<p>
I started the week working on character animation for a small model I had
put together.  I decided I didn't know enough to do that right, and ended
up buying a book: 
<a target=book href="http://www.amazon.com/gp/product/B002YNS62A/ref=docs-os-doi_0">Game Engine Architecture</a>
by Jason Gregory.
It tries to cover the entire range of game engine issues, and on many topics, it's
just a summary with (badly formatted) links.  It does have a pretty extensive chapter 
on character animation.  But the more I read, the more I realized it was a 
huge project.
<p>
I looked around for something else to do for this part, 
and settled on Sound.   The final result of this is just some new code
for the project, but to have some fun with it, I also made a short movie.
Skip to that below if you get bored with the technical stuff.

<h2>Ogg and Vorbis</h2>
<p>
During my previous attempt at this project in 2005, I had worked through 
the spec for Windows DirectSound and written a test program.  Back then, I wasn't
worried about distributing a demo, so I had just used uncompressed Wav files.
This time, I wanted longer pieces of music and so I needed a codec.  I originally
thought I'd use MP3, but some discussion on the net convinced me to use Ogg Vorbis
instead.  There's a reference implementation and supposedly no license issues.
<p>
<a target=Ogg href="http://www.xiph.org/ogg/">Ogg</a> turns
out to be the container format, which can handle a variety of streaming content.  
<a target=vorbis href="http://www.xiph.org/vorbis/">Vorbis</a> is the audio 
codec.  
<p>
With the Vorbis library, there's a sample decoder that reads the Ogg file, decompresses 
the audio with Vorbis and writes it to a file.  There's also "VorbisFile" layer that 
reads an Ogg file without exposing any of the underlying API.  Both of these produce
output buffers of arbitrary length, determined by the size of the compressed packets.
<p>
This was a problem for my DirectSound test program -- it wants me to fill a fixed size buffer.  
Yes, I could have coded around that, but the guts of the Vorbis file layer
are <i>really</i> complicated, since it supports seeking to the middle of 
the file and re-syncing the audio.  Even the simpler decoder example was
a problem -- I need to understand it well enough to unwind the loop, and 
read more audio data when DirectSound needed it, not just run through the
entire file and convert it in one pass.
<p>
I spent a couple of days reading the Ogg and Vorbis documentation and puzzling 
over the example code before I got my version to work.  Ogg
supports "pages" which contain "packets", although packets can apparently span
pages as well.  I also found the names of routines a bit confusing.  Would
you call <i>ogg_sync_pageout</i>, followed by <i>ogg_stream_pagein</i> to start a 
new page?
<p>
Once you work through the docs, it's really simple (simpler than their example, 
actually.) For reference, you structure your code like this:
<p>
<ul>
<li>Read and process the Vorbis header packets from the file.
<li>Start a new page.
</ul>
Write a "readPacket" routine:
<ul>
<li>Try to read a packet.  If this succeeds, you are done.
<li>If it fails with "need more data", read a page.
<li>If this fails with "need more data", read more of the 
source file and push it to Ogg.
<li>Go back to the top and read a packet.
</ul>
<p>
Once you have this routine, decoding the file is simple:
<ul>
<li>Read a packet.
<li>Decode it with Vorbis.
<li>Copy wave data to your audio buffer.
<li>Repeat until you have filled the buffer.
</ul>
If Vorbis returns more data than you want, you can leave
some of it in the codec.  This makes it easy for me to 
just fill the fixed-size audio buffer I use with DirectSound.
After about 20 attempts, music played from my own demo.  Whee!

<h2>OpenAL</h2>
<p>
DirectSound is Windows-only, and I wanted to support other platforms.
<a target=openal href="http://kcat.strangesoft.net/openal.html">OpenAL</a>
was recommended by a reader back early in this blog, and seemed to do 
everything I needed, so I went with that.
<p>
OpenAL builds with CMake, and everything I've done so far under Windows
uses Visual C++ project files.  I really didn't want anyone grabbing 
the code to have to mix different methods of building the libraries,
so I rebuilt the OpenAL library with Visual C++.
<p>
That involved some messing
with configuration files, and one mystery problem with initialization.
I cannot figure out how the original code initializes itself when used
as a static library, not a DLL.  I had to fix that, by bashing it with a rock.
<p>
Unlike DirectSound, which uses Windows Events, the OpenAL API requires you
to poll the various sounds to see if they need more data.  When I saw that,
I imagined some spin loop running in its own thread, burning CPU, but of 
course that's not needed here.  For each sound, the example sets up 
three buffers -- one playing, one ready to play, and a third being loaded.
By making these hold 1 second of audio each, I have plenty to time to load
new data even if the polling loop only checks every half second.
<p>
Once that worked, I wrote a cover for the whole mess -- Ogg, Vorbis and OpenAL -- 
to just support attaching Ogg files to objects and moving them around
in three dimensions.  I packaged it all up as a single audio library, to go with 
the Jpeg lib and my multiplatform "mgFramework" library.

<h2>A Short Rant</h2>
<p>
I know this is all open source and we should be grateful for what we get, 
even if the documentation is a bit terse and the code a bit dense.  But these
guys aren't working on a hobby project.  This is intended to be a reference
implementation of a standard.  And when that's your goal, <i>make the damn
code compile without errors!</i>
<p>
Both Vorbis and OpenAL spit out type conversion warning messages
-- "conversion from 'double' to 'float', possible loss of data" etc.  
The Vorbis code may have been written assuming that library functions like 
"cos" and "floor" return float instead of double.  When I replaced them with
"cosf" and "floorf", a lot of errors were fixed.  
<p>
That can't be the only explanation though.  There are plenty of explicit uses
of the "double" type, and the code mixes float and double constants (0.5f, and 0.5)
freely.  It just seems a bit confused over which floating point type it's using.
I assume that's due to multiple authors, but it's also trivial to fix.  It's not
like this is the first release!  
<p>
The code also consistently rounds numbers by adding 0.5 and truncating to integer, 
without an "(int)" cast, and it assigns pointers without regard to type (void* to char*).  
That doesn't bother the compiler, although the IDE underlines them all as errors.  
And I suppose the code could be really, really old (before C++?), but using "new" and 
"this" as variable names really throws me when reading the code.
<p>
There's even less excuse for this in OpenAL.  It actually defines its own type names for
everything and has conversion routines.  Why would you write something like this
and not explicitly cast the result to shut up the compiler?
<pre>
ALfloat Conv_ALfloat_ALint (ALint val) 
{
  return val * (1.0/2147483647.0); 
}
</pre>
<p>
I went through the Vorbis code and fixed all the warnings, and some of these variable
names.  I didn't fix all the pointer assignments because they don't produce error messages
(and they are everywhere.)  I haven't tackled the OpenAL code yet.  This is really
not the sort of thing I should spend time on...

<h2>A Movie</h2>
<p>
To have some fun with all this code, I decided to make a very short
movie.  A search for music found the piece I was looking for 
in a Wikipedia topic.  As with all the other background music I've used, 
YouTube flags it but doesn't ban the video.
<p>
Next, I needed some sound effects.  I found a cheesy laser weapon sound (free!)
at <a target=audiomicro href="http://www.audiomicro.com/">AudioMicro</a>, 
but was stumped for the flying saucer.  Google just pulled up a 
lot of "spaceship whoosh" sounds, not the classic 1950s saucer warble.  
AudioMicro had an effect that sounded OK, although I needed to edit it.  
Unfortunately, it wasn't free.  After several failed searches for an 
alternative, I just paid the $9 they wanted for it.
<p>
To edit my sounds, I downloaded the 
<a target=audacity href="http://audacity.sourceforge.net/">Audacity</a>
open source sound editor.  This has done everything I needed, although 
that hasn't been much so far.
The resulting movie is <a href="http://www.youtube.com/watch?v=yNOB9Zp-vhw">here.</a>
Trivial as this movie is, it takes a bit of implementation.  Watch it first,
then read the list of steps in the construction.
<p>
The movie program is implemented as a state machine, with each state
transitioning to the next once time or other conditions are satisfied.
<ul>
<li>Look at the stars for a few seconds while the music plays.<p>
<li>Create some saucers and let them pass by for a few seconds.<p>
<li>Create the "broken" saucer offscreen and let it drift to a stop in view.<p>
<li>Create the first "killer" saucer.<p>
<li>Wait a bit, then create the second killer saucer.<p>
<li>Let the first killer come to a stop, then start his attack.<p>
<li>Let the second killer stop, then start his attack.<p>
<li>Attacks continue until broken ship is red hot.<p>
<li>End the beams and wait while the broken ship fades.<p>
<li>Killers start moving again.<p>
<li>Pan towards Earth.<p>
<li>Play background music to end.<p>
</ul>
<p>
None of this is complicated, but the timing does take some fussing to 
get right, as do the camera angles, grouping of ships, etc.  I found
that after working on the video a bit, I lost the ability to tell if
I was presenting things too quickly.  I had to come back to it after
a day and look at it again.
<p>
That's it for this week.  I'm going to release the program that creates
the movie as a demo once I get a few more things cleaned up (and get it
to work on other platforms.)  I'll post a notice when that's available.
I'd like to see if sound works for all of you.
<p>
<table align=center>
<tr><td><img src="http://www.sea-of-memes.com/LetsCode49/minecraft-saucer.jpg"></td></tr>
</table>


]]></content:encoded>
</item>






</channel>
</rss>

