Thursday, March 1, 2007

NeHe Lesson 10: Loading And Moving Through A 3D World

The 10th lesson is finally converted and polished. This lesson shows you how to load world data from a text file and then how to display it. And actually it's pretty simple code. The original lesson can be read here. I'll go over couple things here that are more specific to D and Tango.

First I've imported the world data at compile time into the final executable. This is a cool feature and I think very useful for static data like this. You can of course use it to import texture data or something totally different.

setupWorld(import("world.txt"));
You need at least the version 1.005 of DMD for this to work. I have no idea if GDC even supports this yet. With 1.005 you need to add the relative path to the world.txt to the string above. With 1.006 and later you don't need to change the code, but you must use the -J switch to define the search path for the compiler where it can find the file.

The setupWorld function is pretty simple. With the use of Tango's LineIterator, reading through the world data is a breeze.

Now go play with it, lesson10.d and world.txt.