7 //version = show_frame_time;
10 // ////////////////////////////////////////////////////////////////////////// //
11 static if (__traits(compiles
, () { import arsd
.simpledisplay
; })) {
12 import arsd
.simpledisplay
;
18 __gshared SimpleWindow sdwindow
;
19 public __gshared Image texImage
;
21 shared static ~this () {
25 public enum vlWidth
= 160;
26 public enum vlHeight
= 120;
27 public enum scale
= 3;
28 public enum scanlines
= false;
30 public enum vlEffectiveWidth
= vlWidth
*scale
;
31 public enum vlEffectiveHeight
= vlHeight
*scale
;
34 // ////////////////////////////////////////////////////////////////////////// //
35 __gshared string aftstr
; // average frame time
38 if (sdwindow
.closed
) return;
39 auto painter
= sdwindow
.draw();
40 painter
.drawImage(Point(0, 0), texImage
);
42 //painter.outlineColor = Color.white;
43 painter
.outlineColor
= Color
.black
;
44 painter
.drawText(Point(10, 10), aftstr
);
48 public void mainLoop () {
49 texImage
= new Image(vlEffectiveWidth
, vlEffectiveHeight
);
52 sdwindow
= new SimpleWindow(vlEffectiveWidth
, vlEffectiveHeight
, "RayMarching demo", OpenGlOptions
.no
, Resizablity
.fixedSize
);
55 enum MSecsPerFrame
= 1000/60; /* 60 is FPS */
57 uint[8] frameTimes
= 1000;
59 sdwindow
.eventLoop(MSecsPerFrame
,
61 if (sdwindow
.closed
) return;
62 if (mtrenderComplete
) {
63 // do average frame time
65 foreach (immutable idx
; 1..frameTimes
.length
) {
66 aft
+= frameTimes
.ptr
[idx
];
67 frameTimes
.ptr
[idx
-1] = frameTimes
.ptr
[idx
];
69 frameTimes
[$-1] = mtrenderFrameTime
;
70 aft
+= frameTimes
[$-1];
71 aft
/= cast(uint)frameTimes
.length
;
72 if (aft
== 0) aft
= 1000;
75 aftstr
= "%s FPS".format(1000/aft
);
77 //version(show_frame_time) { import core.stdc.stdio; printf("%u msecs per frame\n", frameDur); }
79 mtrenderStartSignal();
82 delegate (KeyEvent event
) {
83 if (sdwindow
.closed
) return;
84 if (event
.pressed
&& event
.key
== Key
.Escape
) {
89 delegate (MouseEvent event
) {
92 if (ch
== ' ') mtrenderTogglePause();
96 if (!sdwindow
.closed
) {