Titanion 0.4

Robert Jacques sandford at jhu.edu
Mon Apr 27 21:12:46 PDT 2009


On Mon, 27 Apr 2009 17:29:49 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Moritz Warning:
>> Titanion is a 2.5D shooter game for Windows, *nix and MacOSX.
>> The original code by Kenta Cho was ported to use Tango and Derelict.
>
> Lot of fireworks and the code looks clean. Most D games I see have  
> inside a 2D and/or 3D vector struct, and the code is generally  
> essentially the same. To avoid such duplication I think such struct  
> deserves to be in Phobos/Tango.
>
> Bye,
> bearophile

I agree. Actually, it would be really nice if functions were able to  
return static arrays. (See  
http://d.puremagic.com/issues/show_bug.cgi?id=1869)

In the mean time there's

struct Vec(T = float,size_t N = 3) {
     T[N] _data;
     alias _data this;
     string toString() { std.conv.return text(_data); }
}


plus functions as array properties which apparently got upgraded at some  
point to the extra () isn't needed anymore. ( i.e. vec.x instead of  
vec.x() )

i.e.

T x(T, size_t N)(T[N] v) {
     return v[0];
}

And it works pretty well:

Vec!(T,N) foo(T,size_t N)(T[N] v) {
     Vec!(T,N) r = v;
     return r;
}

float bar(float[3] b) {
     return b[0];
}

void main() {
     float[3] x = [1,2,3];
     float[3] y = foo(x);
     Vec!(float,3) z = x;
     writeln(foo(y).x);
     writeln(bar(z));
     writeln(x);
     writeln(y);
//    writeln(foo(z).x); // Issues with being passed to a template
//    writeln(z);        // error in format.d, goes away with when alias  
this is commented out
     writeln(z.toString);
}

hmm...


More information about the Digitalmars-d-announce mailing list