Revision 7eae2d49
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
217 | 217 |
|
218 | 218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
219 | 219 |
|
220 |
public void changeObject(RubikObjectList object, int size)
|
|
220 |
public void changeObject(RubikObjectList newObject, int newSize, boolean reportChange)
|
|
221 | 221 |
{ |
222 | 222 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
223 | 223 |
RubikPreRender pre = view.getPreRender(); |
224 |
pre.changeObject(object,size); |
|
224 |
|
|
225 |
if( reportChange ) |
|
226 |
{ |
|
227 |
RubikObject oldObject = pre.getObject(); |
|
228 |
RubikObjectList oldList = oldObject.getObjectList(); |
|
229 |
int oldSize = oldObject.getSize(); |
|
230 |
float fps = view.getRenderer().getFPS(); |
|
231 |
StringBuilder name = new StringBuilder(); |
|
232 |
name.append(oldList.name()); |
|
233 |
name.append('_'); |
|
234 |
name.append(oldSize); |
|
235 |
name.append(' '); |
|
236 |
name.append(fps); |
|
237 |
name.append(" --> "); |
|
238 |
name.append(newObject.name()); |
|
239 |
name.append('_'); |
|
240 |
name.append(newSize); |
|
241 |
|
|
242 |
if( BuildConfig.DEBUG ) |
|
243 |
{ |
|
244 |
android.util.Log.e("rubik", name.toString()); |
|
245 |
} |
|
246 |
else |
|
247 |
{ |
|
248 |
FirebaseAnalytics analytics = getAnalytics(); |
|
249 |
|
|
250 |
if( analytics!=null ) |
|
251 |
{ |
|
252 |
Bundle bundle = new Bundle(); |
|
253 |
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name.toString()); |
|
254 |
analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
pre.changeObject(newObject,newSize); |
|
225 | 260 |
} |
226 | 261 |
|
227 | 262 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
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() |
src/main/java/org/distorted/states/RubikStatePattern.java | ||
---|---|---|
71 | 71 |
int objectPlay= play.getObject(); |
72 | 72 |
int sizePlay = play.getSize(); |
73 | 73 |
|
74 |
act.changeObject(RubikObjectList.getObject(objectPlay),sizePlay); |
|
74 |
act.changeObject(RubikObjectList.getObject(objectPlay),sizePlay, false);
|
|
75 | 75 |
} |
76 | 76 |
} |
77 | 77 |
|
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
283 | 283 |
{ |
284 | 284 |
if( act.getPreRender().canPlay() && RubikState.getCurrentState()==RubikState.PLAY ) |
285 | 285 |
{ |
286 |
FirebaseAnalytics analytics = act.getAnalytics(); |
|
287 |
|
|
288 |
if( analytics!=null ) |
|
289 |
{ |
|
290 |
String name = RubikObjectList.getObject(obj).name()+"_"+sizes[size]; |
|
291 |
Bundle bundle = new Bundle(); |
|
292 |
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name); |
|
293 |
analytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM, bundle); |
|
294 |
} |
|
295 |
|
|
296 | 286 |
mObject = obj; |
297 | 287 |
mSize = sizes[size]; |
298 |
act.changeObject(list,sizes[size]); |
|
288 |
act.changeObject(list,sizes[size], true);
|
|
299 | 289 |
adjustSpinner(act); |
300 | 290 |
} |
301 | 291 |
|
Also available in: Unified diff
On object change, report FPS to Firebase