comparison demos/qd.d @ 450:22a56b65872b

Trying to get the old QD demo to work.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Fri, 01 Aug 2008 21:55:57 +0200
parents f869c636a113
children 6aaa3d3c1183
comparison
equal deleted inserted replaced
449:56265fa07c7d 450:22a56b65872b
1 module qd; 1 module qd;
2
3 alias char[] string;
2 4
3 extern(C) { 5 extern(C) {
4 struct SDL_Rect { 6 struct SDL_Rect {
5 short x, y; 7 short x, y;
6 ushort w, h; 8 ushort w, h;
105 void getpixel32(int x, int y, ubyte[4] *col) { 107 void getpixel32(int x, int y, ubyte[4] *col) {
106 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x; 108 uint *bufp = cast(uint *)display.pixels + y*display.pitch/4 + x;
107 SDL_GetRGBA(*bufp, display.format, &(*col)[0], &(*col)[1], &(*col)[2], &(*col)[3]); 109 SDL_GetRGBA(*bufp, display.format, &(*col)[0], &(*col)[1], &(*col)[2], &(*col)[3]);
108 } 110 }
109 111
112 align(1)
110 struct rgb { 113 struct rgb {
111 ubyte[3] values; 114 ubyte[3] values;
112 ubyte r() { return values[0]; } 115 ubyte r() { return values[0]; }
113 ubyte g() { return values[1]; } 116 ubyte g() { return values[1]; }
114 ubyte b() { return values[2]; } 117 ubyte b() { return values[2]; }
286 else bresenham!(false, false)(x0, y0, x1, y1); 289 else bresenham!(false, false)(x0, y0, x1, y1);
287 } 290 }
288 } 291 }
289 } 292 }
290 293
291 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f32") { 294 import llvmdc.intrinsics;
292 float sqrt(float val); 295 alias llvm_sqrt_f32 sqrt;
293 } 296 alias llvm_sqrt_f64 sqrt;
294 pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f64") { 297 version(X86)
295 double sqrt(double val); 298 {
296 real sqrt(real val); 299 alias llvm_sqrt_f80 sqrt;
297 } 300 }
301 else
302 {
303 static import tango.stdc.math;
304 real sqrt(real x)
305 {
306 return tango.stdc.math.sqrtl(x);
307 }
308 }
309
298 310
299 template circle_bresenham_pass(bool first) { 311 template circle_bresenham_pass(bool first) {
300 const string xy=(first?"x":"y"); 312 const string xy=(first?"x":"y");
301 const string yx=(first?"y":"x"); 313 const string yx=(first?"y":"x");
302 const string str=" 314 const string str="
324 } 336 }
325 } 337 }
326 "; 338 ";
327 } 339 }
328 340
329 import std.stdio;
330 void circle(T...)(T t) { 341 void circle(T...)(T t) {
331 static assert(T.length!<3, "Circle: Needs x, y and radius"); 342 static assert(T.length!<3, "Circle: Needs x, y and radius");
332 int cx=t[0], cy=t[1], xradius=t[2]; 343 int cx=t[0], cy=t[1], xradius=t[2];
333 SDL_LockSurface(display); 344 SDL_LockSurface(display);
334 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; } 345 scope(exit) { SDL_UnlockSurface(display); if (doFlip) flip; }
432 if (key) key(evt.key.keysym.sym, true); 443 if (key) key(evt.key.keysym.sym, true);
433 case SDL_EventType.KeyUp: 444 case SDL_EventType.KeyUp:
434 if (key) key(evt.key.keysym.sym, false); 445 if (key) key(evt.key.keysym.sym, false);
435 break; 446 break;
436 case SDL_EventType.Quit: 447 case SDL_EventType.Quit:
437 throw new Error("Quit"); 448 throw new Exception("Quit");
438 break; 449 break;
439 default: break; 450 default: break;
440 } 451 }
441 } 452 }
442 } 453 }
452 } 463 }
453 464
454 void events(void delegate(int, bool) key, void delegate(int, int) mouse) { 465 void events(void delegate(int, bool) key, void delegate(int, int) mouse) {
455 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); }); 466 events(key, (int x, int y, ubyte b, bool p) { mouse(x, y); });
456 } 467 }
468
469 void sleep(float secs)
470 {
471 assert(secs >= 0);
472 uint ms = cast(uint)(secs * 1000);
473 SDL_Delay(ms);
474 }