Project

General

Profile

« Previous | Next » 

Revision 7eae2d49

Added by Leszek Koltunski almost 4 years ago

On object change, report FPS to Firebase

View differences:

src/main/java/org/distorted/main/RubikRenderer.java
40 40
{
41 41
   private RubikSurfaceView mView;
42 42
   private DistortedScreen mScreen;
43
   private Fps mFPS;
44

  
45
   private static class Fps
46
     {
47
     private static final int NUM_FRAMES  = 100;
48

  
49
     private long lastTime=0;
50
     private long[] durations;
51
     private int currDuration;
52
     private float currFPS;
53

  
54
     Fps()
55
       {
56
       durations = new long[NUM_FRAMES+1];
57
       currDuration = 0;
58

  
59
       for (int i=0; i<NUM_FRAMES+1; i++) durations[i] = 16;
60
       durations[NUM_FRAMES] = NUM_FRAMES * 16;
61
       }
62

  
63
     void onRender(long time)
64
       {
65
       if( lastTime==0 ) lastTime = time;
66

  
67
       currDuration++;
68
       if (currDuration >= NUM_FRAMES) currDuration = 0;
69
       durations[NUM_FRAMES] += ((time - lastTime) - durations[currDuration]);
70
       durations[currDuration] = time - lastTime;
71

  
72
       currFPS = ((int)(10000.0f*NUM_FRAMES/durations[NUM_FRAMES]))/10.0f;
73

  
74
       lastTime = time;
75
       }
76

  
77
     float getFPS()
78
       {
79
       return currFPS;
80
       }
81
     }
43 82

  
44 83
///////////////////////////////////////////////////////////////////////////////////////////////////
45 84

  
......
48 87
     final float BRIGHTNESS = 0.1f;
49 88

  
50 89
     mView = v;
90
     mFPS = new Fps();
51 91
     mScreen = new DistortedScreen();
52 92
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
53 93
     }
......
59 99
   @Override
60 100
   public void onDrawFrame(GL10 glUnused)
61 101
     {
102
     long time = System.currentTimeMillis();
103
     mFPS.onRender(time);
62 104
     mView.getPreRender().preRender();
63
     mScreen.render( System.currentTimeMillis() );
105
     mScreen.render(time);
64 106
     }
65 107

  
66 108
///////////////////////////////////////////////////////////////////////////////////////////////////
......
126 168
       }
127 169
     }
128 170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
   float getFPS()
174
     {
175
     return mFPS.getFPS();
176
     }
177

  
129 178
///////////////////////////////////////////////////////////////////////////////////////////////////
130 179

  
131 180
   DistortedScreen getScreen()

Also available in: Unified diff