11package br .nullexcept .mux .core .texel ;
22
33import br .nullexcept .mux .C ;
4- import br .nullexcept .mux .app .Activity ;
54import br .nullexcept .mux .app .Looper ;
65import br .nullexcept .mux .graphics .Point ;
7- import br .nullexcept .mux .input . CharEvent ;
6+ import br .nullexcept .mux .graphics . fonts . Typeface ;
87import br .nullexcept .mux .hardware .GLES ;
8+ import br .nullexcept .mux .input .CharEvent ;
99import br .nullexcept .mux .input .KeyEvent ;
1010import br .nullexcept .mux .input .MotionEvent ;
1111import br .nullexcept .mux .input .MouseEvent ;
1212import br .nullexcept .mux .view .View ;
13+ import br .nullexcept .mux .view .ViewGroup ;
1314import br .nullexcept .mux .view .Window ;
1415import org .lwjgl .glfw .GLFW ;
16+ import org .lwjgl .nanovg .NVGColor ;
17+ import org .lwjgl .nanovg .NanoVG ;
1518import org .lwjgl .opengles .GLES20 ;
1619
20+ import static org .lwjgl .glfw .GLFW .glfwSwapInterval ;
21+
1722class GlfwWindow extends Window {
1823 private final long window ;
1924 private final GlfwEventManager eventManager ;
@@ -54,7 +59,7 @@ private void refresh() {
5459 position .set (buffer [0 ][0 ], buffer [1 ][0 ]);
5560 }
5661
57- private int frames = 0 ;
62+ private long [] times = new long [ 8 ] ;
5863 private long last = System .currentTimeMillis ();
5964
6065 private void update () {
@@ -64,13 +69,18 @@ private void update() {
6469
6570 if (System .currentTimeMillis () - last >= 1000 ) {
6671 last = System .currentTimeMillis ();
67- frames = 0 ;
72+ times [5 ] = times [0 ];
73+ times [6 ] = times [1 ] / times [0 ];
74+
75+ times [0 ] = 0 ;
76+ times [1 ] = 0 ;
6877 }
69- frames ++;
78+ times [ 0 ] ++;
7079 eventManager .runFrame ();
7180
7281 long time = System .currentTimeMillis ();
7382 if (isVisible () && container != null ) {
83+ long begin = System .currentTimeMillis ();
7484 int ow = windowSize .x ;
7585 int oh = windowSize .y ;
7686 refresh ();
@@ -80,10 +90,17 @@ private void update() {
8090 container .drawFrame ();
8191 GLFW .glfwSwapBuffers (C .GLFW_CONTEXT );
8292 GLFW .glfwMakeContextCurrent (window );
93+ glfwSwapInterval (0 ); //NEED THAT FOR NOT SLOW MAIN LOOP
8394 GLES .glViewport (0 , 0 , ow , oh );
8495 GLES .glClearColor (0 ,0 ,0 ,1 );
8596 GLES .glClear (GLES20 .GL_COLOR_BUFFER_BIT | GLES20 .GL_DEPTH_BUFFER_BIT | GLES20 .GL_STENCIL_BUFFER_BIT );
8697 GLTexel .drawTexture (0 , 0 , ow , oh , container .getCanvas ().getFramebuffer ().getTexture ());
98+
99+ times [1 ] += System .currentTimeMillis () - begin ;
100+ if (C .Flags .DEBUG_OVERLAY ) {
101+ drawDebug ();
102+ }
103+
87104 GLFW .glfwSwapBuffers (window );
88105 GLFW .glfwMakeContextCurrent (C .GLFW_CONTEXT );
89106 }
@@ -93,13 +110,48 @@ private void update() {
93110 time = System .currentTimeMillis () - time ;
94111 // Window with focus = 60fps | without focus = 24fps
95112 time = Math .max (0 , (isFocused () ? 16 : 41 ) - time );
113+ if (C .Flags .FULL_DRAW ) {
114+ time = 1 ;
115+ }
96116 if (!destroyed ) {
97117 Looper .getMainLooper ().postDelayed (this ::update , time );
98118 } else {
99119 running = false ;
100120 }
101121 }
102122
123+ private final NVGColor color1 = NVGColor .create ();
124+ private final NVGColor color2 = NVGColor .create ();
125+ private void drawDebug () {
126+ NanoVG .nvgBeginFrame (C .VG_CONTEXT ,windowSize .x , windowSize .y ,1 );
127+ NanoVG .nvgFontFaceId (C .VG_CONTEXT , Typeface .DEFAULT .hashCode ());
128+ NanoVG .nvgFontSize (C .VG_CONTEXT , 16 );
129+
130+ NanoVG .nvgBeginPath (C .VG_CONTEXT );
131+ NanoVG .nvgRGBAf (0 ,0 ,0 ,.5f , color2 );
132+ NanoVG .nvgFillColor (C .VG_CONTEXT , color2 );
133+ NanoVG .nvgRect (C .VG_CONTEXT , 10 , 10 , 160 ,72 );
134+ NanoVG .nvgFill (C .VG_CONTEXT );
135+ NanoVG .nvgClosePath (C .VG_CONTEXT );
136+
137+ NanoVG .nvgRGBAf (1 ,1 ,1 ,1 , color1 );
138+ NanoVG .nvgFillColor (C .VG_CONTEXT , color1 );
139+ NanoVG .nvgText (C .VG_CONTEXT ,15 ,32 ,"FPS: " +times [5 ]);
140+ NanoVG .nvgText (C .VG_CONTEXT ,15 ,48 ,"DRAW TIME: " +times [6 ]+"ms" );
141+ NanoVG .nvgText (C .VG_CONTEXT ,15 ,64 ,"VIEWS: " +viewCount (container ));
142+ NanoVG .nvgEndFrame (C .VG_CONTEXT );
143+ }
144+
145+ private int viewCount (ViewGroup container ) {
146+ int count = 0 ;
147+ for (View view : container .getChildren ()) {
148+ if (view instanceof ViewGroup )
149+ count += viewCount ((ViewGroup ) view );
150+ count ++;
151+ }
152+ return count ;
153+ }
154+
103155 private void onResize (int width , int height ) {
104156 if (container != null ) {
105157 container .resize (width , height );
0 commit comments