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
.drawText(Point(10, 10), aftstr
);
47 public void mainLoop () {
48 texImage
= new Image(vlEffectiveWidth
, vlEffectiveHeight
);
51 sdwindow
= new SimpleWindow(vlEffectiveWidth
, vlEffectiveHeight
, "RayMarching demo", OpenGlOptions
.no
, Resizablity
.fixedSize
);
54 enum MSecsPerFrame
= 1000/60; /* 60 is FPS */
56 uint[8] frameTimes
= 1000;
58 sdwindow
.eventLoop(MSecsPerFrame
,
60 if (sdwindow
.closed
) return;
61 if (mtrenderComplete
) {
62 // do average frame time
64 foreach (immutable idx
; 1..frameTimes
.length
) {
65 aft
+= frameTimes
.ptr
[idx
];
66 frameTimes
.ptr
[idx
-1] = frameTimes
.ptr
[idx
];
68 frameTimes
[$-1] = mtrenderFrameTime
;
69 aft
+= frameTimes
[$-1];
70 aft
/= cast(uint)frameTimes
.length
;
71 if (aft
== 0) aft
= 1000;
74 aftstr
= "%s FPS".format(1000/aft
);
76 //version(show_frame_time) { import core.stdc.stdio; printf("%u msecs per frame\n", frameDur); }
78 mtrenderStartSignal();
81 delegate (KeyEvent event
) {
82 if (sdwindow
.closed
) return;
83 if (event
.key
== Key
.Escape
) {
88 delegate (MouseEvent event
) {
94 if (!sdwindow
.closed
) {