annotate demos/qd.d @ 650:aa6a0b7968f7

Added test case for bug #100 Removed dubious check for not emitting static private global in other modules without access. This should be handled properly somewhere else, it's causing unresolved global errors for stuff that should work (in MiniD)
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 05 Oct 2008 17:28:15 +0200
parents 22a56b65872b
children 6aaa3d3c1183
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
38 void SDL_UpdateRect (SDL_Surface *screen, int x, int y, uint w, uint h);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
39 int SDL_UpperBlit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
40 alias SDL_UpperBlit SDL_BlitSurface;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
41 int SDL_SetAlpha(SDL_Surface *surface, uint flags, ubyte alpha);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
42 int SDL_SetColorKey(SDL_Surface *surface, uint flag, uint key);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
48 const uint SDL_SRCALPHA=0x00010000;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
49 const uint SDL_SRCCOLORKEY=0x00001000;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
50 void SDL_Delay(uint ms);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
51 uint SDL_GetTicks();
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
52
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
53 enum SDLKey {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
54 Unknown = 0, First = 0,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
55 Escape = 27,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
56 LCtrl = 306,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
57 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
58 enum SDLMod {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
59 KMOD_NONE = 0x0000,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
60 KMOD_LSHIFT= 0x0001, KMOD_RSHIFT= 0x0002,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
61 KMOD_LCTRL = 0x0040, KMOD_RCTRL = 0x0080, KMOD_CTRL = 0x00C0,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
62 KMOD_LALT = 0x0100, KMOD_RALT = 0x0200, KMOD_ALT = 0x0300,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
63 KMOD_LMETA = 0x0400, KMOD_RMETA = 0x0800,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
64 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
65 KMOD_RESERVED = 0x8000
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
66 };
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
67
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
68 struct SDL_keysym { ubyte scancode; SDLKey sym; SDLMod mod; ushort unicode; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
69 enum SDL_EventType : ubyte {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
70 NoEvent=0, Active, KeyDown, KeyUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
71 MouseMotion, MouseButtonDown, MouseButtonUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
72 JoyAxisMotion, JoyBallMotion, JoyHatMotion, JoyButtonDown, JoyButtonUp,
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
73 Quit, SysWMEvent
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
74 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
75 union SDL_Event {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
76 SDL_EventType type;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
77 struct Active { SDL_EventType type, gain, state; }; Active active;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
78 struct Key { SDL_EventType type, which, state; SDL_keysym keysym; }; Key key;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
79 struct Motion { SDL_EventType type, which, state; ushort x, y; short xrel, yrel; }; Motion motion;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
80 struct Button { SDL_EventType type, which, button, state; ushort x, y; }; Button button;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
81 struct Jaxis { SDL_EventType type, which, axis; short value; }; Jaxis jaxis;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
82 struct Jball { SDL_EventType type, which, ball; short xrel, yrel; }; Jball jball;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
83 struct Jhat { SDL_EventType type, which, hat, value; }; Jhat jhat;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
84 struct Jbutton { SDL_EventType type, which, button, state; }; Jbutton jbutton;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
85 struct Resize { SDL_EventType type; int w, h; }; Resize resize;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
86 struct Expose { SDL_EventType type; }; Expose expose;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
87 struct Quit { SDL_EventType type; }; Quit quit;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
88 struct User { SDL_EventType type; int code; void *data1, data2; }; User user;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
89 struct Syswm { SDL_EventType type; void *msg; }; Syswm syswm;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
90 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
91
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
97 void putpixel32(int x, int y, ubyte[4] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
98 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
102 void putpixel32(int x, int y, ubyte[3] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
103 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
104 *bufp = SDL_MapRGBA(display.format, col[0], col[1], col[2], 0);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
105 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
106
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
107 void getpixel32(int x, int y, ubyte[4] *col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
108 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
115 ubyte r() { return values[0]; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
116 ubyte g() { return values[1]; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
128 void putpixel(int x, int y, ubyte[4] col) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
129 if ( (x<0) || (y<0) || (x!<display.w) || (y!<display.h) ) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
130 putpixel32(x, y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
131 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
132
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
133 void hline(int x, int y, int w, rgb r) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
134 hline(x, y, w, SDL_MapRGBA(display.format, r.values[0], r.values[1], r.values[2], 0));
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
135 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
136 void hline(int x, int y, int w, uint c) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
137 if ( (y<0) || (y!<display.h) ) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
138 if (x<0) { w+=x; x=0; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
139 if (w<0) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
140 if ( (x+w) !<display.w) w=display.w-x-1;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
141 auto cur = cast(uint *)display.pixels + y*display.pitch/4 + x;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
150 const rgb Yellow={[255, 255, 0]};
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
151 const rgb Cyan={[0, 255, 255]};
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
184 bool doFlip=true;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
185 void flip() { SDL_Flip(display); }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
186 void flip(bool target) { doFlip=target; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
187 scope class groupDraws {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
188 bool wasOn;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
189 this() { wasOn=doFlip; flip=false; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
190 ~this() { if (wasOn) { flip=true; flip; } }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
191 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
194 const int bcol=select!(back_rgb, T);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
203 void tintfill(int x1, int y1, int x2, int y2, rgb color) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
204 SDL_LockSurface(display);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
205 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
206 ubyte[4] c;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
207 for (int x=x1; x<x2; ++x) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
208 for (int y=y1; y<y2; ++y) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
209 getpixel32(x, y, &c);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
210 c[0]=cast(ubyte)(c[0]*178+color.r*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
211 c[1]=cast(ubyte)(c[1]*178+color.g*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
212 c[2]=cast(ubyte)(c[2]*178+color.b*77)>>8;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
213 putpixel32(x, y, c);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
214 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
215 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
216 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
250 static if (steep) putpixel(var2, var1, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
264 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
265 auto yend=max(y0, y1);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
266 for (int y=min(y0, y1); y<=yend; ++y) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
450
22a56b65872b Trying to get the old QD demo to work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 85
diff changeset
294 import llvmdc.intrinsics;
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
323 putpixel(cx+x, cy+y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
324 putpixel(cx+x, cy-y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
325 putpixel(cx-x, cy+y, col);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
341 void circle(T...)(T t) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
342 static assert(T.length!<3, "Circle: Needs x, y and radius");
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
345 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
348 if (xradius!>0) return;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
355 hline(cx-j, cy+i, 2*j, back_sdl);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
366 float distance(float x1, float y1, float x2, float y2) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
367 auto x=x1-x2, y=y1-y2;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
368 return sqrt(x*x+y*y);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
369 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
416 struct screen {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
417 static {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
418 void opCall(size_t w, size_t h) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
419 display = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
420 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
421 int width() { return display.w; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
422 int height() { return display.h; }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
426
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
427 void cls(rgb fill=Black) { line(0, 0, display.w-1, display.h-1, Fill=fill); }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
428
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
429 void events(void delegate(int, bool) key=null, void delegate(int, int, ubyte, bool) mouse=null) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
430 SDL_Event evt;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
431 while (SDL_PollEvent(&evt)) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
432 switch (evt.type) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
433 case SDL_EventType.MouseMotion:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
434 with (evt.motion) if (mouse) mouse(x, y, 0, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
435 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
436 case SDL_EventType.MouseButtonDown:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
437 with (evt.button) if (mouse) mouse(x, y, button, true);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
438 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
439 case SDL_EventType.MouseButtonUp:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
440 with (evt.button) if (mouse) mouse(x, y, button, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
441 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
442 case SDL_EventType.KeyDown:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
443 if (key) key(evt.key.keysym.sym, true);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
444 case SDL_EventType.KeyUp:
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
445 if (key) key(evt.key.keysym.sym, false);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
446 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
449 break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
450 default: break;
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
451 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
452 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
453 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
454
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
455 void events(void delegate(int) key, void delegate(int, int, ubyte, bool) mouse=null) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
456 events((int a, bool b) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
457 if (b) key(a);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
458 }, mouse);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
459 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
460
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
461 void events(void delegate(int) key, void delegate(int, int) mouse) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
462 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); });
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
463 }
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
464
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
465 void events(void delegate(int, bool) key, void delegate(int, int) mouse) {
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
466 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); });
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 41
diff changeset
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 }