1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.main;
|
11
|
|
12
|
import android.annotation.SuppressLint;
|
13
|
import android.app.ActivityManager;
|
14
|
import android.content.Context;
|
15
|
import android.content.pm.ConfigurationInfo;
|
16
|
import android.opengl.GLES30;
|
17
|
import android.opengl.GLSurfaceView;
|
18
|
import android.util.AttributeSet;
|
19
|
import android.view.MotionEvent;
|
20
|
|
21
|
import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
22
|
|
23
|
import org.distorted.external.RubikScores;
|
24
|
import org.distorted.library.main.DistortedScreen;
|
25
|
import org.distorted.objectlib.main.ObjectControl;
|
26
|
import org.distorted.objectlib.main.TwistyObjectNode;
|
27
|
import org.distorted.overlays.DataStars;
|
28
|
import org.distorted.overlays.OverlayStars;
|
29
|
import org.distorted.screens.ScreenList;
|
30
|
|
31
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
|
33
|
public class RubikSurfaceView extends GLSurfaceView
|
34
|
{
|
35
|
private ObjectControl mObjectController;
|
36
|
private RubikOSInterface mInterface;
|
37
|
private RubikRenderer mRenderer;
|
38
|
private int mScreenWidth, mScreenHeight;
|
39
|
private boolean mCreated;
|
40
|
private boolean mShowStars;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
void setScreenSize(int width, int height)
|
45
|
{
|
46
|
mScreenWidth = width;
|
47
|
mScreenHeight= height;
|
48
|
mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)));
|
49
|
|
50
|
if( !mCreated )
|
51
|
{
|
52
|
mCreated = true;
|
53
|
mObjectController.createNode(width,height);
|
54
|
TwistyObjectNode objectNode = mObjectController.getNode();
|
55
|
objectNode.glDepthMask(false);
|
56
|
objectNode.glStencilMask(0);
|
57
|
mRenderer.getScreen().attach(objectNode);
|
58
|
|
59
|
if( mShowStars )
|
60
|
{
|
61
|
mShowStars = false;
|
62
|
RubikScores scores = RubikScores.getInstance();
|
63
|
int totStars = scores.getNumStars();
|
64
|
DistortedScreen screen = mRenderer.getScreen();
|
65
|
OverlayStars stars = new OverlayStars();
|
66
|
DataStars data = new DataStars(totStars,0,getResources());
|
67
|
stars.startOverlay(screen,null,data);
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
|
74
|
void setShowStars()
|
75
|
{
|
76
|
mShowStars = true;
|
77
|
}
|
78
|
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
|
81
|
boolean isVertical()
|
82
|
{
|
83
|
return mScreenHeight>mScreenWidth;
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
RubikRenderer getRenderer()
|
89
|
{
|
90
|
return mRenderer;
|
91
|
}
|
92
|
|
93
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94
|
|
95
|
ObjectControl getObjectControl()
|
96
|
{
|
97
|
return mObjectController;
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
// PUBLIC API
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
public RubikSurfaceView(Context context, AttributeSet attrs)
|
105
|
{
|
106
|
super(context,attrs);
|
107
|
|
108
|
mCreated = false;
|
109
|
mShowStars = false;
|
110
|
|
111
|
if(!isInEditMode())
|
112
|
{
|
113
|
RubikActivity act = (RubikActivity)context;
|
114
|
RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
|
115
|
mInterface = new RubikOSInterface(act);
|
116
|
mObjectController = new ObjectControl(ref,mInterface);
|
117
|
mRenderer = new RubikRenderer(this);
|
118
|
|
119
|
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
120
|
|
121
|
try
|
122
|
{
|
123
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
124
|
int esVersion = configurationInfo.reqGlEsVersion>>16;
|
125
|
setEGLContextClientVersion(esVersion);
|
126
|
setRenderer(mRenderer);
|
127
|
}
|
128
|
catch(Exception ex)
|
129
|
{
|
130
|
act.OpenGLError();
|
131
|
|
132
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
133
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
134
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
135
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
136
|
|
137
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
138
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
139
|
crashlytics.setCustomKey("GL version" , version );
|
140
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
141
|
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
142
|
crashlytics.recordException(ex);
|
143
|
}
|
144
|
}
|
145
|
}
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
@Override
|
150
|
public void onPause()
|
151
|
{
|
152
|
super.onPause();
|
153
|
mObjectController.onPause();
|
154
|
}
|
155
|
|
156
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157
|
|
158
|
@Override
|
159
|
public void onResume()
|
160
|
{
|
161
|
super.onResume();
|
162
|
mObjectController.onResume();
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
|
167
|
@SuppressLint("ClickableViewAccessibility")
|
168
|
@Override
|
169
|
public boolean onTouchEvent(MotionEvent event)
|
170
|
{
|
171
|
int mode = ScreenList.getMode();
|
172
|
return mObjectController.onTouchEvent(event,mode);
|
173
|
}
|
174
|
}
|
175
|
|