Archive for March, 2007
Saturday, March 17th, 2007
The latest beta of Tango is out. Read the changelog or go straight to the download page. Those new to Tango might want to start from the beginning. Installation instructions are also available.
Technorati Tags: D Programming Language, Tango
Posted in Tango | No Comments »
Wednesday, March 14th, 2007
If you understand Chinese, you might be interested in paying a visit to DLang. My Korean is far from perfect, but it’s a far sight better than my Chinese (anything is better than my Chinese — excluding, of course, Japanese). So while I don’t know specifically what they’re posting over there, enough English is showing up to know that it’s all about D. It looks to be quite an active community. I’d love to learn more about it.
I should also mention ideage, from the same domain, which looks to be a blog about D. Again, it’s all in Chinese. Lots of good stuff to look at there, though, even if you don’t understand it all. Such as the code from a post on D Singletons, which covers a great more bases than what I posted recently.
Now I want to go out and learn how to read Chinese.
Technorati Tags: D Programming Language, China
Posted in News | 3 Comments »
Sunday, March 11th, 2007
Sometimes you need to execute different code paths depending upon certain runtime parameters. For example, in graphics applications it is quite common to create different rendering paths based upon the graphics API features supported by the user’s graphics card. In simple cases, this can be handled with an if…else block, or perhaps a switch. More complex cases need more. In C, you might set function pointers during app startup. In C++ or Java, you might use different implementations of an interface or of an abstract class. In D, you can do many of the same things as other languages. You can also put all of your variable code paths in one class, rather than subclasses or different interface implementations, and let instances configure themselves in the constructor using delegates.
Here’s a simple example that configures an instance of a class based upon the value of a static counter:
// selfdelegate.d
import std.stdio;
class Printer
{
public:
this()
{
if(count++ == 0)
print = ¬hingPrinter;
else
print = &somethingPrinter;
}
void delegate() print; // delegate configured during instantiation
private:
void nothingPrinter()
{
writefln(”Nothing.”);
}
void somethingPrinter()
{
writefln(”Something”);
}
static int count = 0;
}
void main()
{
Printer p1 = new Printer;
Printer p2 = new Printer;
p1.print();
p2.print();
}
Here’s a sample execution:
C:\projects\D\tests>dmd -run selfdelegate
Nothing.
Something
If you have many methods that need to be configured, you may prefer to use a factory and instantiate different implementations of an interface. That approach limits you to some extent, however.
For example, consider an OpenGL renderer interface that has three implementations: an advanced version, an intermediate version requiring at least version 1.x of OpenGL, and a legacy version for OpenGL 1.1. What if the user’s graphics card doesn’t support a few of the extensions used by the advanced version, but does support most of them? With the set up described, you’d have no choice but to fall back to the intermediate or legacy version. Wouldn’t it be better if you could make use of the advanced features that are supported and use fallbacks only for those that aren’t? There are several different ways to mix and match like that. Using delegates for a class to configure itself at runtime is one you might not have thought of.
Technorati Tags: D Programming Language, delegates
Posted in Code, D Programming | No Comments »
Sunday, March 11th, 2007
Skipping a public release of 1.008 (it was a “special build”), Walter has given us DMD 1.009. No new or changed features in this release — it’s all about bugs.
Technorati Tags: D Programming Language, DMD, Digital Mars, Walter Bright
Posted in DMD Releases | No Comments »
Saturday, March 10th, 2007
In the late nineties when I got (a really late) start in toying around with game development, Allegro was the library I used for my experimentations. I once started work on a Java binding for it. Though I haven’t looked at it in years, Allegro still holds a special place in my heart (sob). Now, torhu has given us version 2.0 of the D binding to Allegro that he took over from someone else. From the NG announcement:
dallegro 2.0 is a new set of D bindings for Allegro. It’s primarily tested on Windows, but is reported to work on linux. It’s also likely to work on MacOS X, although untested so far.
A bunch of examples, plus a larger demo game is included in the dallegro download. They are all direct ports of regular Allegro’s C versions, and are primarily used for verifying that dallegro works. They are obviously not good examples of D programming. I plan to add a simple Tetris clone as an example of a D game using dallegro.
dallegro is compatible with both Phobos and Tango. Which revisions of Tango it compiles with is a bit unclear at the moment, but 1856 seems to work.
The dallegro API is the same as for C version, so just follow the Allegro manual. Differences are noted in readme.txt.
I normally don’t like to post direct download links, but I’ll make an exception this time: this is a direct link to dallegro_20_beta4.zip. You can read more about it in torhu’s Allegro forums post.
Technorati Tags: D Programming Language, game programming, Allegro
Posted in Gamedev/Games, News | No Comments »