Mercurial > projects > ldc
annotate demos/qd.d @ 323:0d52412d5b1a trunk
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
Changed the way moduleinfo is registered to use the same approach as DMD, this eliminates the need for correct linking order and should make the way for using a natively compiled runtime library. This should speed up linking tremendously and should now be possible.
Fixed the llvm.used array to only be emitted if really necessary.
author | lindquist |
---|---|
date | Wed, 09 Jul 2008 23:43:51 +0200 |
parents | f869c636a113 |
children | 22a56b65872b |
rev | line source |
---|---|
73 | 1 module qd; |
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
|
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
|
3 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
|
4 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
|
5 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
|
6 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
|
7 } |
835320b88ad6
[svn 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 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
|
9 //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
|
10 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
|
11 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
|
12 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
|
13 } |
835320b88ad6
[svn 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 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
|
15 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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 } |
835320b88ad6
[svn 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 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
|
30 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
|
31 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
|
32 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
|
33 SDL_Surface * SDL_SetVideoMode(int width, int height, int bpp, uint flags); |
73 | 34 SDL_Surface *SDL_CreateRGBSurface(uint flags, int width, int height, int depth, uint Rmask=0, uint Gmask=0, uint Bmask=0, uint Amask=0); |
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
|
35 int SDL_Flip(SDL_Surface *); |
73 | 36 void SDL_UpdateRect (SDL_Surface *screen, int x, int y, uint w, uint h); |
37 int SDL_UpperBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); | |
38 alias SDL_UpperBlit SDL_BlitSurface; | |
39 int SDL_SetAlpha(SDL_Surface *surface, uint flags, ubyte alpha); | |
40 int SDL_SetColorKey(SDL_Surface *surface, uint flag, uint key); | |
41 int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, uint color); | |
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
|
42 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
|
43 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
|
44 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
|
45 const uint SDL_FULLSCREEN=0x80000000; |
73 | 46 const uint SDL_SRCALPHA=0x00010000; |
47 const uint SDL_SRCCOLORKEY=0x00001000; | |
48 void SDL_Delay(uint ms); | |
49 uint SDL_GetTicks(); | |
50 | |
51 enum SDLKey { | |
52 Unknown = 0, First = 0, | |
53 Escape = 27, | |
54 LCtrl = 306, | |
55 } | |
56 enum SDLMod { | |
57 KMOD_NONE = 0x0000, | |
58 KMOD_LSHIFT= 0x0001, KMOD_RSHIFT= 0x0002, | |
59 KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_CTRL = 0x00C0, | |
60 KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_ALT = 0x0300, | |
61 KMOD_LMETA = 0x0400, KMOD_RMETA = 0x0800, | |
62 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000, | |
63 KMOD_RESERVED = 0x8000 | |
64 }; | |
65 | |
66 struct SDL_keysym { ubyte scancode; SDLKey sym; SDLMod mod; ushort unicode; } | |
67 enum SDL_EventType : ubyte { | |
68 NoEvent=0, Active, KeyDown, KeyUp, | |
69 MouseMotion, MouseButtonDown, MouseButtonUp, | |
70 JoyAxisMotion, JoyBallMotion, JoyHatMotion, JoyButtonDown, JoyButtonUp, | |
71 Quit, SysWMEvent | |
72 } | |
73 union SDL_Event { | |
74 SDL_EventType type; | |
75 struct Active { SDL_EventType type, gain, state; }; Active active; | |
76 struct Key { SDL_EventType type, which, state; SDL_keysym keysym; }; Key key; | |
77 struct Motion { SDL_EventType type, which, state; ushort x, y; short xrel, yrel; }; Motion motion; | |
78 struct Button { SDL_EventType type, which, button, state; ushort x, y; }; Button button; | |
79 struct Jaxis { SDL_EventType type, which, axis; short value; }; Jaxis jaxis; | |
80 struct Jball { SDL_EventType type, which, ball; short xrel, yrel; }; Jball jball; | |
81 struct Jhat { SDL_EventType type, which, hat, value; }; Jhat jhat; | |
82 struct Jbutton { SDL_EventType type, which, button, state; }; Jbutton jbutton; | |
83 struct Resize { SDL_EventType type; int w, h; }; Resize resize; | |
84 struct Expose { SDL_EventType type; }; Expose expose; | |
85 struct Quit { SDL_EventType type; }; Quit quit; | |
86 struct User { SDL_EventType type; int code; void *data1, data2; }; User user; | |
87 struct Syswm { SDL_EventType type; void *msg; }; Syswm syswm; | |
88 } | |
89 | |
90 int SDL_PollEvent(SDL_Event *event); | |
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
|
91 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
94 |
73 | 95 void putpixel32(int x, int y, ubyte[4] col) { |
96 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
97 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], col[3]); | |
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
|
98 } |
835320b88ad6
[svn 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 |
73 | 100 void putpixel32(int x, int y, ubyte[3] col) { |
101 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
102 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], 0); | |
103 } | |
104 | |
105 void getpixel32(int x, int y, ubyte[4] *col) { | |
106 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
107 SDL_GetRGBA(*bufp, display.format, &(*col)[0], &(*col)[1], &(*col)[2], &(*col)[3]); | |
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
|
108 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
111 ubyte[3] values; |
73 | 112 ubyte r() { return values[0]; } |
113 ubyte g() { return values[1]; } | |
114 ubyte b() { return values[2]; } | |
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
|
115 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
|
116 rgb res; |
73 | 117 foreach (id, ref v; res.values) v=cast(ubyte)((values[id]+other.values[id])/2); |
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
|
118 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
|
119 } |
835320b88ad6
[svn 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 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
|
121 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
|
122 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 |
73 | 125 void putpixel(int x, int y, ubyte[4] col) { |
126 if ( (x<0) || (y<0) || (x!<display.w) || (y!<display.h) ) return; | |
127 putpixel32(x, y, col); | |
128 } | |
129 | |
130 void hline(int x, int y, int w, rgb r) { | |
131 hline(x, y, w, SDL_MapRGBA(display.format, r.values[0], r.values[1], r.values[2], 0)); | |
132 } | |
133 void hline(int x, int y, int w, uint c) { | |
134 if ( (y<0) || (y!<display.h) ) return; | |
135 if (x<0) { w+=x; x=0; } | |
136 if (w<0) return; | |
137 if ( (x+w) !<display.w) w=display.w-x-1; | |
138 auto cur = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
139 foreach (ref value; cur[0..w+1]) value=c; | |
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
|
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 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
|
143 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
|
144 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
|
145 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
|
146 const rgb Blue={[0, 0, 255]}; |
73 | 147 const rgb Yellow={[255, 255, 0]}; |
148 const rgb Cyan={[0, 255, 255]}; | |
149 const rgb Purple={[255, 0, 255]}; | |
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
|
150 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
|
151 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
|
152 |
835320b88ad6
[svn 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 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
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 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 |
73 | 181 bool doFlip=true; |
182 void flip() { SDL_Flip(display); } | |
183 void flip(bool target) { doFlip=target; } | |
184 scope class groupDraws { | |
185 bool wasOn; | |
186 this() { wasOn=doFlip; flip=false; } | |
187 ~this() { if (wasOn) { flip=true; flip; } } | |
188 } | |
189 | |
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
|
190 void execParams(T...)(T params) { |
73 | 191 const int bcol=select!(back_rgb, T); |
192 static if (bcol != -1) back=cast(rgb) params[bcol]; | |
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
|
193 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
|
194 static if (col != -1) color=params[col]; |
73 | 195 else static if (bcol != -1) color=back; |
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
|
196 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
|
197 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
|
198 } |
835320b88ad6
[svn 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 |
73 | 200 void tintfill(int x1, int y1, int x2, int y2, rgb color) { |
201 SDL_LockSurface(display); | |
202 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } | |
203 ubyte[4] c; | |
204 for (int x=x1; x<x2; ++x) { | |
205 for (int y=y1; y<y2; ++y) { | |
206 getpixel32(x, y, &c); | |
207 c[0]=cast(ubyte)(c[0]*178+color.r*77)>>8; | |
208 c[1]=cast(ubyte)(c[1]*178+color.g*77)>>8; | |
209 c[2]=cast(ubyte)(c[2]*178+color.b*77)>>8; | |
210 putpixel32(x, y, c); | |
211 } | |
212 } | |
213 } | |
214 | |
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
|
215 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
|
216 SDL_LockSurface(display); |
73 | 217 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
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
|
218 execParams(params); |
73 | 219 putpixel32(x, y, color.values); |
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
|
220 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
223 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
|
224 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
|
225 ubyte[4] c; |
73 | 226 getpixel32(x, y, &c); |
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
|
227 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
|
228 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 void swap(T)(ref T a, ref T b) { T c=a; a=b; b=c; } |
73 | 231 T abs(T)(T a) { return (a<0) ? -a : a; } |
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
|
232 |
835320b88ad6
[svn 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 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 } 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
|
240 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
|
241 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
|
242 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
|
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 auto error = 0f; |
73 | 245 ubyte[4] col; col[0..3]=color.values; |
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
|
246 for (auto var1 = mixin(name~'0'); var1 <= mixin(name~'1'); ++var1) { |
73 | 247 static if (steep) putpixel(var2, var1, col); |
248 else putpixel(var1, var2, col); | |
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
|
249 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
|
250 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
|
251 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
255 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
|
256 |
835320b88ad6
[svn 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 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
|
258 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
|
259 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
|
260 SDL_LockSurface(display); |
73 | 261 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
262 auto yend=max(y0, y1); | |
263 for (int y=min(y0, y1); y<=yend; ++y) { | |
264 hline(min(x0, x1), y, max(x0, x1)-min(x0, x1), back); | |
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
|
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 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 } |
835320b88ad6
[svn 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 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
|
274 SDL_LockSurface(display); |
73 | 275 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 } 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
|
285 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
|
286 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
|
287 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 |
78
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
291 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f32") { |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
292 float sqrt(float val); |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
293 } |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
294 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f64") { |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
295 double sqrt(double val); |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
296 real sqrt(real val); |
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
297 } |
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
|
298 |
835320b88ad6
[svn 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 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 while (stopx"~(first?">=":"<=")~"stopy) { |
73 | 311 putpixel(cx+x, cy+y, col); |
312 putpixel(cx+x, cy-y, col); | |
313 putpixel(cx-x, cy+y, col); | |
314 putpixel(cx-x, cy-y, col); | |
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
|
315 "~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
|
316 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
|
317 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
|
318 "~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
|
319 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
|
320 --"~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
|
321 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
|
322 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
|
323 "~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
|
324 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
325 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
326 "; |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
327 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
328 |
73 | 329 import std.stdio; |
330 void circle(T...)(T t) { | |
331 static assert(T.length!<3, "Circle: Needs x, y and radius"); | |
332 int cx=t[0], cy=t[1], xradius=t[2]; | |
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
|
333 SDL_LockSurface(display); |
73 | 334 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
335 execParams(t[3..$]); | |
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
|
336 auto yradius=xradius; |
73 | 337 if (xradius!>0) return; |
338 static if (T.length>3 && is(T[3]: int)) yradius=t[3]; | |
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
|
339 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
|
340 auto ratio=xradius*1f/yradius; |
73 | 341 auto back_sdl=SDL_MapRGBA(display.format, back.values[0], back.values[1], back.values[2], 0); |
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
|
342 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
|
343 ushort j=cast(ushort)(sqrt(cast(real)(yradius*yradius-i*i))*ratio); |
73 | 344 hline(cx-j, cy+i, 2*j, back_sdl); |
345 hline(cx-j, cy-i, 2*j, back_sdl); | |
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
|
346 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
347 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
348 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
|
349 auto y2square=2*yradius*yradius; |
73 | 350 ubyte[4] col; col[0..3]=color.values; |
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
|
351 { 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
|
352 { 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
|
353 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
354 |
73 | 355 float distance(float x1, float y1, float x2, float y2) { |
356 auto x=x1-x2, y=y1-y2; | |
357 return sqrt(x*x+y*y); | |
358 } | |
359 | |
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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
367 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
368 |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
369 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
|
370 SDL_LockSurface(display); |
73 | 371 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
377 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 //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
|
395 for (int i=e+1; i<w; ++i) { |
73 | 396 putpixel32(i, y, color.values); |
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
|
397 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
|
398 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
|
399 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
400 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
401 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
402 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
403 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
404 |
73 | 405 struct screen { |
406 static { | |
407 void opCall(size_t w, size_t h) { | |
408 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE | SDL_DOUBLEBUF); | |
409 } | |
410 int width() { return display.w; } | |
411 int height() { return display.h; } | |
412 } | |
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
|
413 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
414 |
73 | 415 |
416 void cls(rgb fill=Black) { line(0, 0, display.w-1, display.h-1, Fill=fill); } | |
417 | |
418 void events(void delegate(int, bool) key=null, void delegate(int, int, ubyte, bool) mouse=null) { | |
419 SDL_Event evt; | |
420 while (SDL_PollEvent(&evt)) { | |
421 switch (evt.type) { | |
422 case SDL_EventType.MouseMotion: | |
423 with (evt.motion) if (mouse) mouse(x, y, 0, false); | |
424 break; | |
425 case SDL_EventType.MouseButtonDown: | |
426 with (evt.button) if (mouse) mouse(x, y, button, true); | |
427 break; | |
428 case SDL_EventType.MouseButtonUp: | |
429 with (evt.button) if (mouse) mouse(x, y, button, false); | |
430 break; | |
431 case SDL_EventType.KeyDown: | |
432 if (key) key(evt.key.keysym.sym, true); | |
433 case SDL_EventType.KeyUp: | |
434 if (key) key(evt.key.keysym.sym, false); | |
435 break; | |
436 case SDL_EventType.Quit: | |
437 throw new Error("Quit"); | |
438 break; | |
439 default: break; | |
440 } | |
441 } | |
442 } | |
443 | |
444 void events(void delegate(int) key, void delegate(int, int, ubyte, bool) mouse=null) { | |
445 events((int a, bool b) { | |
446 if (b) key(a); | |
447 }, mouse); | |
448 } | |
449 | |
450 void events(void delegate(int) key, void delegate(int, int) mouse) { | |
451 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
452 } | |
453 | |
454 void events(void delegate(int, bool) key, void delegate(int, int) mouse) { | |
455 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
456 } |