Mercurial > projects > ldc
annotate demos/qd.d @ 761:fa306ca8843b
Applied fvbommel's patch from #112
Added missing TypeInfoInvariant codegen for D2
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 12 Nov 2008 02:30:28 +0100 |
parents | 6aaa3d3c1183 |
children |
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 |
450
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
3 alias char[] string; |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
4 |
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
|
5 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
|
6 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
|
7 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
|
8 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
|
9 } |
835320b88ad6
[svn 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 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
|
11 //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
|
12 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
|
13 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
|
14 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
|
15 } |
835320b88ad6
[svn 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 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 } |
835320b88ad6
[svn 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 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
|
32 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
|
33 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
|
34 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
|
35 SDL_Surface * SDL_SetVideoMode(int width, int height, int bpp, uint flags); |
73 | 36 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
|
37 int SDL_Flip(SDL_Surface *); |
73 | 38 void SDL_UpdateRect (SDL_Surface *screen, int x, int y, uint w, uint h); |
39 int SDL_UpperBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); | |
40 alias SDL_UpperBlit SDL_BlitSurface; | |
41 int SDL_SetAlpha(SDL_Surface *surface, uint flags, ubyte alpha); | |
42 int SDL_SetColorKey(SDL_Surface *surface, uint flag, uint key); | |
43 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
|
44 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
|
45 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
|
46 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
|
47 const uint SDL_FULLSCREEN=0x80000000; |
73 | 48 const uint SDL_SRCALPHA=0x00010000; |
49 const uint SDL_SRCCOLORKEY=0x00001000; | |
50 void SDL_Delay(uint ms); | |
51 uint SDL_GetTicks(); | |
52 | |
53 enum SDLKey { | |
54 Unknown = 0, First = 0, | |
55 Escape = 27, | |
56 LCtrl = 306, | |
57 } | |
58 enum SDLMod { | |
59 KMOD_NONE = 0x0000, | |
60 KMOD_LSHIFT= 0x0001, KMOD_RSHIFT= 0x0002, | |
61 KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_CTRL = 0x00C0, | |
62 KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_ALT = 0x0300, | |
63 KMOD_LMETA = 0x0400, KMOD_RMETA = 0x0800, | |
64 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000, | |
65 KMOD_RESERVED = 0x8000 | |
66 }; | |
67 | |
68 struct SDL_keysym { ubyte scancode; SDLKey sym; SDLMod mod; ushort unicode; } | |
69 enum SDL_EventType : ubyte { | |
70 NoEvent=0, Active, KeyDown, KeyUp, | |
71 MouseMotion, MouseButtonDown, MouseButtonUp, | |
72 JoyAxisMotion, JoyBallMotion, JoyHatMotion, JoyButtonDown, JoyButtonUp, | |
73 Quit, SysWMEvent | |
74 } | |
75 union SDL_Event { | |
76 SDL_EventType type; | |
77 struct Active { SDL_EventType type, gain, state; }; Active active; | |
78 struct Key { SDL_EventType type, which, state; SDL_keysym keysym; }; Key key; | |
79 struct Motion { SDL_EventType type, which, state; ushort x, y; short xrel, yrel; }; Motion motion; | |
80 struct Button { SDL_EventType type, which, button, state; ushort x, y; }; Button button; | |
81 struct Jaxis { SDL_EventType type, which, axis; short value; }; Jaxis jaxis; | |
82 struct Jball { SDL_EventType type, which, ball; short xrel, yrel; }; Jball jball; | |
83 struct Jhat { SDL_EventType type, which, hat, value; }; Jhat jhat; | |
84 struct Jbutton { SDL_EventType type, which, button, state; }; Jbutton jbutton; | |
85 struct Resize { SDL_EventType type; int w, h; }; Resize resize; | |
86 struct Expose { SDL_EventType type; }; Expose expose; | |
87 struct Quit { SDL_EventType type; }; Quit quit; | |
88 struct User { SDL_EventType type; int code; void *data1, data2; }; User user; | |
89 struct Syswm { SDL_EventType type; void *msg; }; Syswm syswm; | |
90 } | |
91 | |
92 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
|
93 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
96 |
73 | 97 void putpixel32(int x, int y, ubyte[4] col) { |
98 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
99 *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
|
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
|
101 |
73 | 102 void putpixel32(int x, int y, ubyte[3] col) { |
103 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
104 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], 0); | |
105 } | |
106 | |
107 void getpixel32(int x, int y, ubyte[4] *col) { | |
108 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
109 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
|
110 } |
835320b88ad6
[svn 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 |
450
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
112 align(1) |
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
|
113 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
|
114 ubyte[3] values; |
73 | 115 ubyte r() { return values[0]; } |
116 ubyte g() { return values[1]; } | |
117 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
|
118 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
|
119 rgb res; |
73 | 120 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
|
121 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
|
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 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
|
124 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
|
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 } |
835320b88ad6
[svn 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 |
73 | 128 void putpixel(int x, int y, ubyte[4] col) { |
129 if ( (x<0) || (y<0) || (x!<display.w) || (y!<display.h) ) return; | |
130 putpixel32(x, y, col); | |
131 } | |
132 | |
133 void hline(int x, int y, int w, rgb r) { | |
134 hline(x, y, w, SDL_MapRGBA(display.format, r.values[0], r.values[1], r.values[2], 0)); | |
135 } | |
136 void hline(int x, int y, int w, uint c) { | |
137 if ( (y<0) || (y!<display.h) ) return; | |
138 if (x<0) { w+=x; x=0; } | |
139 if (w<0) return; | |
140 if ( (x+w) !<display.w) w=display.w-x-1; | |
141 auto cur = cast(uint *)display.pixels + y*display.pitch/4 + x; | |
142 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
|
143 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
146 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
|
147 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
|
148 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
|
149 const rgb Blue={[0, 0, 255]}; |
73 | 150 const rgb Yellow={[255, 255, 0]}; |
151 const rgb Cyan={[0, 255, 255]}; | |
152 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
|
153 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
|
154 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
|
155 |
835320b88ad6
[svn 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 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
|
157 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
|
158 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
|
159 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
|
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 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
|
162 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
165 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
|
166 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
|
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 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 |
73 | 184 bool doFlip=true; |
185 void flip() { SDL_Flip(display); } | |
186 void flip(bool target) { doFlip=target; } | |
187 scope class groupDraws { | |
188 bool wasOn; | |
189 this() { wasOn=doFlip; flip=false; } | |
190 ~this() { if (wasOn) { flip=true; flip; } } | |
191 } | |
192 | |
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 void execParams(T...)(T params) { |
73 | 194 const int bcol=select!(back_rgb, T); |
195 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
|
196 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
|
197 static if (col != -1) color=params[col]; |
73 | 198 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
|
199 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
|
200 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
|
201 } |
835320b88ad6
[svn 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 |
73 | 203 void tintfill(int x1, int y1, int x2, int y2, rgb color) { |
204 SDL_LockSurface(display); | |
205 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } | |
206 ubyte[4] c; | |
207 for (int x=x1; x<x2; ++x) { | |
208 for (int y=y1; y<y2; ++y) { | |
209 getpixel32(x, y, &c); | |
210 c[0]=cast(ubyte)(c[0]*178+color.r*77)>>8; | |
211 c[1]=cast(ubyte)(c[1]*178+color.g*77)>>8; | |
212 c[2]=cast(ubyte)(c[2]*178+color.b*77)>>8; | |
213 putpixel32(x, y, c); | |
214 } | |
215 } | |
216 } | |
217 | |
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 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
|
219 SDL_LockSurface(display); |
73 | 220 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
|
221 execParams(params); |
73 | 222 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
|
223 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
226 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
|
227 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
|
228 ubyte[4] c; |
73 | 229 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
|
230 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
|
231 } |
835320b88ad6
[svn 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 swap(T)(ref T a, ref T b) { T c=a; a=b; b=c; } |
73 | 234 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
|
235 |
835320b88ad6
[svn 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 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 } 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
|
243 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
|
244 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
|
245 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
|
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 auto error = 0f; |
73 | 248 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
|
249 for (auto var1 = mixin(name~'0'); var1 <= mixin(name~'1'); ++var1) { |
73 | 250 static if (steep) putpixel(var2, var1, col); |
251 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
|
252 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
|
253 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
|
254 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 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
|
258 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
|
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 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
|
261 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
|
262 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
|
263 SDL_LockSurface(display); |
73 | 264 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
265 auto yend=max(y0, y1); | |
266 for (int y=min(y0, y1); y<=yend; ++y) { | |
267 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
|
268 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 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
|
271 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
|
272 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
|
273 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
|
274 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
|
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 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
|
277 SDL_LockSurface(display); |
73 | 278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 } 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
|
288 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
|
289 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
|
290 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
450
diff
changeset
|
294 import ldc.intrinsics; |
450
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
295 alias llvm_sqrt_f32 sqrt; |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
296 alias llvm_sqrt_f64 sqrt; |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
297 version(X86) |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
298 { |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
299 alias llvm_sqrt_f80 sqrt; |
78
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
300 } |
450
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
301 else |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
302 { |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
303 static import tango.stdc.math; |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
304 real sqrt(real x) |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
305 { |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
306 return tango.stdc.math.sqrtl(x); |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
307 } |
78
2332006e1fa4
[svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents:
73
diff
changeset
|
308 } |
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
|
309 |
450
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
310 |
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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 while (stopx"~(first?">=":"<=")~"stopy) { |
73 | 323 putpixel(cx+x, cy+y, col); |
324 putpixel(cx+x, cy-y, col); | |
325 putpixel(cx-x, cy+y, col); | |
326 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
|
327 "~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
|
328 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
|
329 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
|
330 "~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
|
331 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
|
332 --"~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
|
333 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
|
334 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
|
335 "~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
|
336 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
337 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
338 "; |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn 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 |
73 | 341 void circle(T...)(T t) { |
342 static assert(T.length!<3, "Circle: Needs x, y and radius"); | |
343 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
|
344 SDL_LockSurface(display); |
73 | 345 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } |
346 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
|
347 auto yradius=xradius; |
73 | 348 if (xradius!>0) return; |
349 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
|
350 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
|
351 auto ratio=xradius*1f/yradius; |
73 | 352 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
|
353 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
|
354 ushort j=cast(ushort)(sqrt(cast(real)(yradius*yradius-i*i))*ratio); |
73 | 355 hline(cx-j, cy+i, 2*j, back_sdl); |
356 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
|
357 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
358 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
359 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
|
360 auto y2square=2*yradius*yradius; |
73 | 361 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
|
362 { 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
|
363 { 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
|
364 } |
835320b88ad6
[svn 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 |
73 | 366 float distance(float x1, float y1, float x2, float y2) { |
367 auto x=x1-x2, y=y1-y2; | |
368 return sqrt(x*x+y*y); | |
369 } | |
370 | |
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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 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
|
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 } |
835320b88ad6
[svn 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 |
835320b88ad6
[svn 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 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
|
381 SDL_LockSurface(display); |
73 | 382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 } |
835320b88ad6
[svn 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 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
|
390 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
|
391 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
|
392 } |
835320b88ad6
[svn 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 (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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 //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
|
406 for (int i=e+1; i<w; ++i) { |
73 | 407 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
|
408 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
|
409 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
|
410 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
411 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
412 } |
835320b88ad6
[svn 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 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
415 |
73 | 416 struct screen { |
417 static { | |
418 void opCall(size_t w, size_t h) { | |
419 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE | SDL_DOUBLEBUF); | |
420 } | |
421 int width() { return display.w; } | |
422 int height() { return display.h; } | |
423 } | |
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
|
424 } |
835320b88ad6
[svn r45] Added a modified version of scrapple.qd (by downs) to the demos dir. It doesn't compile yet though :(
lindquist
parents:
diff
changeset
|
425 |
73 | 426 |
427 void cls(rgb fill=Black) { line(0, 0, display.w-1, display.h-1, Fill=fill); } | |
428 | |
429 void events(void delegate(int, bool) key=null, void delegate(int, int, ubyte, bool) mouse=null) { | |
430 SDL_Event evt; | |
431 while (SDL_PollEvent(&evt)) { | |
432 switch (evt.type) { | |
433 case SDL_EventType.MouseMotion: | |
434 with (evt.motion) if (mouse) mouse(x, y, 0, false); | |
435 break; | |
436 case SDL_EventType.MouseButtonDown: | |
437 with (evt.button) if (mouse) mouse(x, y, button, true); | |
438 break; | |
439 case SDL_EventType.MouseButtonUp: | |
440 with (evt.button) if (mouse) mouse(x, y, button, false); | |
441 break; | |
442 case SDL_EventType.KeyDown: | |
443 if (key) key(evt.key.keysym.sym, true); | |
444 case SDL_EventType.KeyUp: | |
445 if (key) key(evt.key.keysym.sym, false); | |
446 break; | |
447 case SDL_EventType.Quit: | |
450
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
448 throw new Exception("Quit"); |
73 | 449 break; |
450 default: break; | |
451 } | |
452 } | |
453 } | |
454 | |
455 void events(void delegate(int) key, void delegate(int, int, ubyte, bool) mouse=null) { | |
456 events((int a, bool b) { | |
457 if (b) key(a); | |
458 }, mouse); | |
459 } | |
460 | |
461 void events(void delegate(int) key, void delegate(int, int) mouse) { | |
462 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
463 } | |
464 | |
465 void events(void delegate(int, bool) key, void delegate(int, int) mouse) { | |
466 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); | |
467 } | |
450
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
468 |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
469 void sleep(float secs) |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
470 { |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
471 assert(secs >= 0); |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
472 uint ms = cast(uint)(secs * 1000); |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
473 SDL_Delay(ms); |
22a56b65872b
Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
85
diff
changeset
|
474 } |