Mercurial > projects > ldc
annotate demos/qd.d @ 54:28e99b04a132 trunk
[svn r58] Fixed cond expression resulting in a non-basic type.
Fixed identity expression for dynamic arrays.
Revamped the system to keep track of lvalues and rvalues and their relations.
Typedef declaration now generate the custom typeinfo.
Other bugfixes.
author | lindquist |
---|---|
date | Wed, 24 Oct 2007 01:37:34 +0200 |
parents | 835320b88ad6 |
children | b706170e24a9 |
rev | line source |
---|---|
41
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
1 // modified version of scrapple.qd to work with llvmdc |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
2 import std.stdio; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
3 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
4 //version(none) |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
5 void main() { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
6 screen(640, 480); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
7 pset(10, 10); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
8 line(0, 0, 100, 100, Box, Back(Red~Black)); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
9 for (int i=0; i<=100; i+=10) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
10 line(i, 0, 100-i, 100); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
11 line(0, i, 100, 100-i); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
12 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
13 circle(100, 100, 50, 15, White~Black, Fill=White~Black); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
14 paint(200, 200, Red, Back=White); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
15 circle(100, 100, 50, 15, White); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
16 paint(200, 200, Black); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
17 pset(10, 11); pset(10, 11, Black); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
18 pset(10, 10); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
19 SDL_Delay(5000); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
20 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
21 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
22 extern(C) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
23 struct SDL_Rect { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
24 short x, y; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
25 ushort w, h; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
26 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
27 struct SDL_PixelFormat { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
28 //SDL_Palette *palette; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
29 void *palette; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
30 ubyte BitsPerPixel, BytesPerPixel, Rloss, Gloss, Bloss, Aloss, Rshift, Gshift, Bshift, Ashift; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
31 uint Rmask, Gmask, Bmask, Amask, colorkey; ubyte alpha; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
32 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
33 struct SDL_Surface { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
34 uint flags; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
35 SDL_PixelFormat *format; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
36 int w, h; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
37 ushort pitch; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
38 void *pixels; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
39 int offset; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
40 void *hwdata; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
41 SDL_Rect clip_rect; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
42 uint unused; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
43 uint locked; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
44 void *map; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
45 uint format_version; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
46 int refcount; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
47 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
48 uint SDL_MapRGBA(SDL_PixelFormat *format, ubyte r, ubyte g, ubyte b, ubyte a); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
49 void SDL_GetRGBA(uint pixel, SDL_PixelFormat *fmt, ubyte *r, ubyte *g, ubyte *b, ubyte *a); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
50 int SDL_LockSurface(SDL_Surface *); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
51 void SDL_UnlockSurface(SDL_Surface *); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
52 SDL_Surface * SDL_SetVideoMode(int width, int height, int bpp, uint flags); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
53 int SDL_Flip(SDL_Surface *); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
54 void SDL_Delay(uint); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
55 const uint SDL_SWSURFACE=0; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
56 const uint SDL_HWSURFACE=1; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
57 const uint SDL_DOUBLEBUF=0x40000000; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
58 const uint SDL_FULLSCREEN=0x80000000; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
59 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
60 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
61 SDL_Surface *display; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
62 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
63 void putpixel32(SDL_Surface *surf, int x, int y, ubyte[4] col) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
64 uint *bufp = cast(uint *)surf.pixels + y*surf.pitch/4 + x; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
65 *bufp = SDL_MapRGBA(surf.format, col[0], col[1], col[2], col[3]); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
66 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
67 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
68 void getpixel32(SDL_Surface *surf, int x, int y, ubyte[4] *col) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
69 uint *bufp = cast(uint *)surf.pixels + y*surf.pitch/4 + x; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
70 SDL_GetRGBA(*bufp, surf.format, &(*col)[0], &(*col)[1], &(*col)[2], &(*col)[3]); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
71 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
72 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
73 struct rgb { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
74 ubyte[3] values; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
75 rgb opCat(rgb other) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
76 rgb res; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
77 foreach (id, ref v; res.values) v=(values[id]+other.values[id])/2; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
78 return res; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
79 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
80 bool opEquals(rgb r) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
81 return values == r.values; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
82 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
83 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
84 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
85 void putpixel(SDL_Surface *surf, int x, int y, rgb c) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
86 if ( (x<0) || (y<0) || (x!<surf.w) || (y!<surf.h) ) return; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
87 putpixel32(surf, x, y, [c.values[0], c.values[1], c.values[2], 0]); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
88 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
89 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
90 const rgb White={[255, 255, 255]}; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
91 const rgb Black={[0, 0, 0]}; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
92 const rgb Red={[255, 0, 0]}; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
93 const rgb Green={[0, 255, 0]}; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
94 const rgb Blue={[0, 0, 255]}; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
95 rgb color=White; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
96 rgb back=Black; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
97 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
98 template failfind(U, T...) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
99 static if (T.length) |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
100 static if (is(T[0] == U)) static assert(false, "Duplicate "~U.stringof~" found!"); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
101 else const bool failfind=failfind!(U, T[1..$]); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
102 else |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
103 const bool failfind=true; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
104 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
105 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
106 template select(U, T...) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
107 static if(T.length) |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
108 static if (is(U == T[0])) { static if (failfind!(U, T[1..$])) { }; const int select = 0; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
109 else |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
110 static if (select!(U, T[1..$]) != -1) |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
111 const int select = 1 + select!(U, T[1..$]); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
112 else |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
113 const int select = -1; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
114 else |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
115 const int select = -1; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
116 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
117 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
118 typedef rgb back_rgb; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
119 back_rgb Back(rgb r) { return cast(back_rgb) r; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
120 back_rgb Back() { return cast(back_rgb) back; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
121 typedef rgb box_rgb; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
122 box_rgb Box(rgb r) { return cast(box_rgb) r; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
123 box_rgb Box() { return cast(box_rgb) color; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
124 alias Back Fill; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
125 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
126 void execParams(T...)(T params) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
127 const int col=select!(rgb, T); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
128 static if (col != -1) color=params[col]; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
129 const int bcol=select!(back_rgb, T); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
130 static if (bcol != -1) back=cast(rgb) params[bcol]; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
131 const int boxcol=select!(box_rgb, T); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
132 static if (boxcol != -1) color=cast(rgb) params[boxcol]; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
133 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
134 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
135 void pset(T...)(int x, int y, T params) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
136 SDL_LockSurface(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
137 scope(exit) { SDL_UnlockSurface(display); SDL_Flip(display); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
138 execParams(params); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
139 putpixel(display, x, y, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
140 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
141 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
142 rgb pget(int x, int y) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
143 SDL_LockSurface(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
144 scope(exit) SDL_UnlockSurface(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
145 ubyte[4] c; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
146 getpixel32(display, x, y, &c); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
147 rgb res; res.values[]=c[0..3]; return res; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
148 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
149 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
150 void swap(T)(ref T a, ref T b) { T c=a; a=b; b=c; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
151 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
152 T abs(T)(T f) { return f < 0 ? -f : f; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
153 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
154 void bresenham(bool countUp=true, bool steep=false)(int x0, int y0, int x1, int y1) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
155 auto deltax = x1 - x0, deltay = y1 - y0; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
156 static if (steep) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
157 auto Δerror = cast(float)deltax / cast(float)deltay; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
158 auto var2 = x0; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
159 const string name="y"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
160 } else { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
161 auto Δerror = cast(float)deltay / cast(float)deltax; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
162 auto var2 = y0; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
163 const string name="x"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
164 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
165 auto error = 0f; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
166 for (auto var1 = mixin(name~'0'); var1 <= mixin(name~'1'); ++var1) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
167 static if (steep) putpixel(display, var2, var1, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
168 else putpixel(display, var1, var2, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
169 error += Δerror; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
170 if (abs(error) >= 1f) { static if (countUp) { var2++; error -= 1f; } else { var2--; error += 1f; }} |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
171 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
172 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
173 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
174 T max(T)(T a, T b) { return a>b?a:b; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
175 T min(T)(T a, T b) { return a<b?a:b; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
176 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
177 void line(T...)(int x0, int y0, int x1, int y1, T p) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
178 execParams(p); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
179 static if (select!(back_rgb, T)!=-1) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
180 SDL_LockSurface(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
181 scope(exit) { SDL_UnlockSurface(display); SDL_Flip(display); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
182 auto xend=max(x0, x1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
183 for (int x=min(x0, x1); x<=xend; ++x) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
184 auto yend=max(y0, y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
185 for (int y=min(y0, y1); y<=yend; ++y) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
186 putpixel(display, x, y, back); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
187 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
188 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
189 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
190 static if (select!(box_rgb, T)!=-1) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
191 line(x0, y0, x1, y0); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
192 line(x1, y0, x1, y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
193 line(x1, y1, x0, y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
194 line(x0, y1, x0, y0); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
195 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
196 static if (select!(box_rgb, T)+select!(back_rgb, T)==-2) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
197 SDL_LockSurface(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
198 scope(exit) { SDL_UnlockSurface(display); SDL_Flip(display); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
199 bool steep = abs(y1 - y0) > abs(x1 - x0); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
200 void turn() { swap(x0, x1); swap(y0, y1); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
201 if (steep) { if (y1 < y0) turn; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
202 else { if (x1 < x0) turn; } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
203 bool stepUp=steep ? (x0 < x1) : (y0 < y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
204 if (steep) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
205 if (stepUp) bresenham!(true, true)(x0, y0, x1, y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
206 else bresenham!(false, true)(x0, y0, x1, y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
207 } else { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
208 if (stepUp) bresenham!(true, false)(x0, y0, x1, y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
209 else bresenham!(false, false)(x0, y0, x1, y1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
210 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
211 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
212 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
213 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
214 import llvm.intrinsic; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
215 alias llvm_sqrt sqrt; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
216 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
217 template circle_bresenham_pass(bool first) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
218 const string xy=(first?"x":"y"); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
219 const string yx=(first?"y":"x"); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
220 const string str=" |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
221 auto x="~(first?"xradius":"0")~"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
222 auto y="~(first?"0":"yradius")~"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
223 auto xchange=yradius*yradius*"~(first?"(1-2*xradius)":"1")~"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
224 auto ychange=xradius*xradius*"~(first?"1":"(1-2*yradius)")~"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
225 auto error=0; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
226 auto stopx="~(first?"y2square*xradius":"0")~"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
227 auto stopy="~(first?"0":"x2square*yradius")~"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
228 while (stopx"~(first?">=":"<=")~"stopy) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
229 putpixel(display, cx+x, cy+y, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
230 putpixel(display, cx+x, cy-y, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
231 putpixel(display, cx-x, cy+y, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
232 putpixel(display, cx-x, cy-y, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
233 "~yx~"++; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
234 stop"~yx~"+="~xy~"2square; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
235 error+="~yx~"change; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
236 "~yx~"change+="~xy~"2square; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
237 if ((2*error+"~xy~"change)>0) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
238 --"~xy~"; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
239 stop"~xy~"-="~yx~"2square; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
240 error+="~xy~"change; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
241 "~xy~"change+="~yx~"2square; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
242 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
243 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
244 "; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
245 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
246 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
247 void circle(T...)(int cx, int cy, int xradius, T t) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
248 SDL_LockSurface(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
249 scope(exit) { SDL_UnlockSurface(display); SDL_Flip(display); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
250 execParams(t); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
251 auto yradius=xradius; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
252 static if (T.length && is(T[0]: int)) yradius=t[0]; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
253 static if (select!(back_rgb, T) != -1) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
254 auto ratio=xradius*1f/yradius; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
255 for (int i=0; i<=yradius; ++i) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
256 ushort j=cast(ushort)(sqrt(cast(real)(yradius*yradius-i*i))*ratio); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
257 for (int lx=cx-j; lx<=cx+j; ++lx) putpixel(display, lx, cy+i, back); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
258 for (int lx=cx-j; lx<=cx+j; ++lx) putpixel(display, lx, cy-i, back); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
259 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
260 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
261 auto x2square=2*xradius*xradius; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
262 auto y2square=2*yradius*yradius; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
263 { mixin(circle_bresenham_pass!(true).str); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
264 { mixin(circle_bresenham_pass!(false).str); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
265 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
266 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
267 struct floodfill_node { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
268 int x, y; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
269 static floodfill_node opCall(int x, int y) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
270 floodfill_node res; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
271 res.x=x; res.y=y; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
272 return res; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
273 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
274 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
275 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
276 void paint(T...)(int x, int y, T t) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
277 SDL_LockSurface(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
278 scope(exit) { SDL_UnlockSurface(display); SDL_Flip(display); } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
279 execParams(t); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
280 bool border=true; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
281 if (select!(back_rgb, T) == -1) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
282 back=pget(x, y); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
283 border=false; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
284 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
285 bool check(rgb r) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
286 if (border) return (r != back) && (r != color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
287 else return r == back; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
288 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
289 if (back == color) throw new Exception("Having identical backgrounds and foregrounds will severely mess up floodfill."); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
290 alias floodfill_node node; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
291 node[] queue; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
292 queue ~= node(x, y); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
293 size_t count=0; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
294 while (count<queue.length) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
295 scope(exit) count++; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
296 with (queue[count]) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
297 if (check(pget(x, y))) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
298 int w=x, e=x; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
299 if (w<display.w) do w++; while ((w<display.w) && check(pget(w, y))); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
300 if (e>=0) do e--; while (e>=0 && check(pget(e, y))); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
301 //SDL_Flip(display); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
302 for (int i=e+1; i<w; ++i) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
303 putpixel(display, i, y, color); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
304 if (y && check(pget(i, y-1)) && ((i==w-1)||!check(pget(i+1, y-1)))) queue ~= node(i, y-1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
305 if ((y < display.h-1) && check(pget(i, y+1)) && ((i==w-1)||!check(pget(i+1, y+1)))) queue ~= node(i, y+1); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
306 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
307 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
308 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
309 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
310 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
311 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
312 void screen(size_t w, size_t h) { |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
313 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE); |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
314 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
315 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
316 void cls() { line(0, 0, display.w-1, display.h-1, Fill=Black); } |