Setting up Arclib with DSSS and Tango
Hello All, this is my first blog post in many years, so bear with me if I mess this WordPress thing up completely
Last weekend, I toyed around with setting up the arcade game programming library for D, called Arclib. Much like the D programming language, Arclib hasn’t fully matured yet, but what’s there looks great!
The guys at the Arclib website have set up an installation guide, which unfortunately isn’t completely up to date, so I figured to take it onto myself to write a quick rundown of what steps I had to take, to get it working:
- install the D compiler
- install DSSS
- install Tango using DSSS
- install Arclib
- create an example d application, using the Arclib tutorial
1) What’s the deal with D, anyway?
Let’s start out with number one. As some of you might know, D is a relatively new programming language (i’m saying relatively, because it’s been a few years under way, but hit v. 1.0 early this year) , and looks a bit like the love child of C++ and JavaScript. I’m saying this in the most positive way possible.
The D language was designed by Walter Bright, who has been making C++ compilers since God know when. Walter does a good job at describing what D is and why we need another programming language.
Installing the compiler is fairly easy:
- Fetch dmd and dmc from DigitalMars.com
- Unpack said zip files onto your drive somewhere (In this example, we’ll be putting them in a folder called C:\D, which I’ll refer to hereafter as your D root)
- Configure your Windows PATH variable to include the compiler’s binary folder.
Once you’ve unpacked your dmd and dmc archives, you should have two folders in your D root, called dm and dmd. We’ll be adding a new folder soon, called dsss, but I’ll get back to that in a moment.
To add dm and dmd’s binaries to the path, open your Windows Control Panel –> System Properties –> Advanced –> Environment Variables and find the System Variables section. In there should be an item called Path, for which you click Edit. In the text field, you add: C:\D\dmd\bin;C:\D\dm\bin;c:\d\dsss\bin; (we might as well add dsss to the path, as it will save us to re-edit the Path variable later). Also, make sure you’ve got semi-colons ; separating your path entries from each other and the existing path entries.
Now that the compiler has been installed, you should test if it works:
Go to your command prompt (cmd) and try:
C:\> DMD
If the output is “Digital Mars D Compiler v1.030” and a lot of usage info, as opposed to ‘DMD’ is not recognized as an internal or external command, operable program or batch file, then congratulations! You’ve installed DMD correctly.
2) DSSS
I must admit, I find it fairly difficult to describe exactly what DSSS is, so instead I’ll quote the DSSS web page:
DSSS, the D Shared Software System, builds upon rebuild and intends to create a standardized system for building, installing, configuring, acquiring and using D software, licensed as Free and Open Source Software under the MIT license: http://www.opensource.org/licenses/mit-license.php . One notable component of it is its net module, which provides an analogue to Perl’s CPAN or Ruby’s Gems for the D programming language.
The current version of DSSS is 0.73 and you can download it here. We will need DSSS to download and install Arclib, Tango and all the components they are built upon. Once you’ve downloaded the DSSS archive, make sure to extract and rename it to dsss instead of dsss-0.73-dmd-win. If you set up the path like I mentioned it, a few paragraphs up, then you’re finished installing DSSS.
To test it, once again venture into your trusted command prompt and try:
C:\> dsss
Hopefully it will tell you “DSSS version 0.73” and you’ll be good to go. If not, then you should probably verify that you added c:\d\dsss\bin to your Path variable.
3) Tango
Now, unless your goal with D is programming different variants of Hello World, I suggest that you update your D environment with a new software library, called Tango.
Basically, Tango is a replacement for the standard software library, called Phobos, which is bundled with DMD. The rationale behind Tango, is that as long most of the official D development is spent on maturing D as a language, development and maintenance on Phobos will never get the attention it rightfully deserves. Tango is a community-driven replacement with (and I quote) “a wide array of general purpose functionality, a complete D runtime layer, optimized garbage collector, a collection package, and a number of text-oriented packages templated for each of utf8, utf16 and utf32. More specialized capabilities include IO selectors, locks, fibers, and meta-processing.” (source)
To install tango, we’ll use DSSS.
C:\> dsss net install tango
DSSS will then ask you which mirror you’d like (pick #1) and it will start downloading the software packages.
Notice: The installation application will at some point come up and ask if you are sure that you want to replace the standard software library with Tango, and once it is installed, we can proceed to install Arclib…
4) Installing Arclib
The final step is installing Arclib. Well almost. We will eventually need to copy a DLL file or two, into your development folder, but we’ll wait with that till we actually need it.
C:\> dsss net install arclib-core
During the installation, you’ll get swarmed with compiler-output, don’t worry, though, unless it actually stops with an error message, the installation should be completed by the time it is over.
5) Making that first Arc application
When you write the source code for your application, you’ll need some kind of text-editor or IDE. Preferably one that allowed you to invoke external applications, allowing you to build your application using ‘dsss build’. (yes, it’s that simple!)
- Pick a text editor. In this case, let’s go with Programmer’s Notepad, since it’s free (as in speech.. and beer!). Alternatively, you could pick from some of the upcoming IDE projects that support D programming. (Personally, i’m a happy user of an Eclipse plugin, called descent, if you wish to try that solution, you just need to follow the instruction guide lines on the descent website)
- Create a folder for your projects, in that, create a new folder for this particular project.
- In your text editor, create a new file in the new folder, called main.d
- For the sake of the example, let’s say this was how you placed your files and folders; c:\d\projects\example\main.d
- In the example folder (the one that holds your main.d file), create a new file called dsss.conf, in this file we’ll tell DSSS about your project, so it is able to build it easily with ‘dsss build‘.
- The contents of your dsss.conf is one line; [main.d] - this tells DSSS the name of the file it needs to build.
This section is using a code example taken from one of the Arclib tutorials, with a few modifications that were required to make it compile.
module main;
// include input, window, and font to display ‘hello world’
import
arc.input,
arc.window,
arc.font,
arc.math.point,
arc.draw.color;
/**
* References: http://dmedia.dprogramming.com/?n=Tutorials.ArcIntro
* http://dsource.org/projects/arclib/wiki/Documentation
* */
int main()
{
// Open window with title, screen width, height, and bits per pixel
arc.window.open(”Hello World”, 400,300,0);
// Open input handling
arc.input.open();
// Open font system
arc.font.open();
// Create a new font with height of 20
Font font = new Font(”font.ttf”, 20);
// while the user doesn’t press the QUIT button
while (!arc.input.keyDown(ARC_QUIT))
{
// process input
arc.input.process();
// clear the current screen
arc.window.clear();
// draw the font in the center of the screen
font.draw(”Hello Arc World”c, Point(200,200),Color.Green);
// swap window buffers
arc.window.swap();
}
// close font system
arc.font.close();
// clean ourselves up and exit
arc.window.close();
return 0;
}
Now that we got the source code laid out, you should try compiling it, using dsss build.
There are a few external files, you may need to run your application. One is sdl_image.dll, another is zlib.dll and finally you will need the font.ttf file from the original Arc tutorial.
6) Further Reading
I’ve round up a few interesting guides and blogs to follow at this point:D Projects:
D Blogs:
- The One with D - Keeps track on a lot of D-related news and announcements
- DMedia - Has a few useful tutorials on Derelict and Arc