1 module edraw
is aliced
;
7 import arsd
.simpledisplay
;
13 import iv
.nanovg
.oui
.blendish
;
14 //import iv.nanovg.svg;
15 import iv
.nanovg
.perf
;
22 // ////////////////////////////////////////////////////////////////////////// //
23 __gshared string RcDir
= "~/.xreader";
24 __gshared string stateFileName
;
26 __gshared
int rotx
, rotz
;
29 // ////////////////////////////////////////////////////////////////////////// //
35 // ////////////////////////////////////////////////////////////////////////// //
39 bool fpsVisible
= false;
46 if (GWidth
< 32) GWidth
= 32;
47 if (GHeight
< 32) GHeight
= 32;
52 import std
.path
: expandTilde
;
53 textFont
= vg
.createFont("text:noaa", "~/ttf/ms/arial.ttf".expandTilde
);
54 uiFont
= vg
.createFont("ui:noaa", "~/ttf/ms/verdana.ttf".expandTilde
);
60 //setOpenGLContextVersion(3, 2); // up to GLSL 150
61 setOpenGLContextVersion(2, 0); // it's enough
62 //openGLContextCompatible = false;
64 auto sdwindow
= new SimpleWindow(GWidth
, GHeight
, "Elite Demo", OpenGlOptions
.yes
, Resizablity
.allowResizing
);
65 //sdwindow.hideCursor();
67 auto stt
= MonoTime
.currTime
;
68 auto prevt
= MonoTime
.currTime
;
70 float dt = 0, secs
= 0;
71 bool needRedraw
= true;
72 MonoTime nextIfTime
= MonoTime
.currTime
;
76 foreach (ref l
; ifs
) {
77 if (l
.speed
== 0) continue;
81 if (l
.y
< l
.ey
) l
.speed
= 0;
83 if (l
.y
> l
.ey
) l
.speed
= 0;
89 foreach (ref l
; ifs
) {
90 if (l
.speed
== 0) continue;
92 vg
.fillColor(nvgRGB(0, 40, 0));
93 vg
.rect(0, l
.y
-1, GWidth
, 3);
99 import std
.random
: uniform
;
102 while (idx
< ifs
.length
&& ifs
[idx
].speed
!= 0) ++idx
;
103 if (idx
>= ifs
.length
) {
104 if (ifs
.length
> 10) return;
105 ifs
~= Interference();
107 if (uniform
!"[]"(0, 1) == 0) {
109 ifs
[idx
].y
= GHeight
/2+uniform
!"[]"(50, GHeight
/2-100);
110 int ty
= ifs
[idx
].y
-40;
112 ifs
[idx
].ey
= uniform
!"[]"(0, ty
);
113 ifs
[idx
].speed
= -uniform
!"[]"(1, 25);
116 ifs
[idx
].y
= GHeight
/2-uniform
!"[]"(50, GHeight
/2-100);
117 int ty
= ifs
[idx
].y
+40;
118 if (ty
>= GHeight
) return;
119 ifs
[idx
].ey
= uniform
!"[]"(ty
, GHeight
);
120 ifs
[idx
].speed
= uniform
!"[]"(1, 25);
126 sdwindow
.closeQuery
= delegate () { doQuit
= true; };
128 void closeWindow () {
129 if (!sdwindow
.closed
&& vg
!is null) {
130 //vg.deleteImage(vgimg);
138 sdwindow
.visibleForTheFirstTime
= delegate () {
139 sdwindow
.setAsCurrentOpenGlContext(); // make this window active
140 sdwindow
.vsync
= false;
141 //sdwindow.useGLFinish = false;
142 //glbindLoadFunctions();
144 vg
= createGL2NVG(NVG_ANTIALIAS|NVG_STENCIL_STROKES|NVG_DEBUG
);
147 writeln("Could not init nanovg.");
151 fps
= new PerfGraph("Frame Time", PerfGraph
.Style
.FPS
, "ui");
153 sdwindow
.redrawOpenGlScene();
156 sdwindow
.windowResized
= delegate (int w
, int h
) {
157 //writeln("w=", w, "; h=", h);
158 glViewport(0, 0, w
, h
);
163 sdwindow
.redrawOpenGlScene
= delegate () {
166 curt
= MonoTime
.currTime
;
167 secs
= cast(double)((curt
-stt
).total
!"msecs")/1000.0;
168 dt = cast(double)((curt
-prevt
).total
!"msecs")/1000.0;
170 //glClearColor(0, 0, 0, 0);
171 glClearColor(0.2, 0.2, 0.2, 0);
172 glClear(glNVGClearFlags
);
175 if (fps
!is null) fps
.update(dt);
176 vg
.beginFrame(GWidth
, GHeight
, 1);
179 drawElite(model
, skin
, rotx
, rotz
, 0, 0, GWidth
, GHeight
);
182 if (fps
!is null && fpsVisible
) fps
.render(vg
, GWidth
-fps
.width
-4, GHeight
-fps
.height
-4);
185 needRedraw
= (fps
!is null && fpsVisible
);
188 sdwindow
.eventLoop(1000/60,
190 if (sdwindow
.closed
) return;
191 if (doQuit
) { closeWindow(); return; }
193 auto ct
= MonoTime
.currTime
;
194 if (ct
>= nextIfTime
) {
195 import std
.random
: uniform
;
196 if (uniform
!"[]"(0, 100) >= 50) addIf();
197 nextIfTime
+= (uniform
!"[]"(50, 1500)).msecs
;
204 if (skip
) rotx
= (rotx
+1)%120;
208 if (needRedraw
) sdwindow
.redrawOpenGlSceneNow();
210 delegate (KeyEvent event
) {
211 if (sdwindow
.closed
) return;
212 if (!event
.pressed
) return;
214 case Key
.Escape
: sdwindow
.close(); break;
215 case Key
.P
: fpsVisible
= !fpsVisible
; needRedraw
= true; break;
216 case Key
.C
: addIf(); break;
220 delegate (MouseEvent event
) {
222 delegate (dchar ch
) {
223 if (ch
== 'q') { doQuit
= true; return; }
230 // ////////////////////////////////////////////////////////////////////////// //
231 void main (string
[] args
) {
232 string shipName
= "escpod";
233 if (args
.length
> 1) shipName
= args
[1];
234 //model = loadModel(VFile("data/"~shipName~".emd"));
235 //skin = loadSkin(VFile("data/"~shipName~".esk"));
237 writeModelText(VFile("zmdl_00.txt", "w"), model
);
238 writeSkinText(VFile("zskn_00.txt", "w"), skin
);