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.os.OSInterface;
|
28
|
import org.distorted.overlays.DataStars;
|
29
|
import org.distorted.overlays.OverlayStars;
|
30
|
import org.distorted.screens.ScreenList;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public class RubikSurfaceView extends GLSurfaceView
|
35
|
{
|
36
|
private ObjectControl mObjectController;
|
37
|
private OSInterface mInterface;
|
38
|
private RubikRenderer mRenderer;
|
39
|
private int mScreenWidth, mScreenHeight;
|
40
|
private boolean mCreated;
|
41
|
private boolean mShowStars;
|
42
|
|
43
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44
|
|
45
|
void setScreenSize(int width, int height)
|
46
|
{
|
47
|
mScreenWidth = width;
|
48
|
mScreenHeight= height;
|
49
|
mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)));
|
50
|
|
51
|
if( !mCreated )
|
52
|
{
|
53
|
mCreated = true;
|
54
|
mObjectController.createNode(width,height);
|
55
|
TwistyObjectNode objectNode = mObjectController.getNode();
|
56
|
objectNode.glDepthMask(false);
|
57
|
objectNode.glStencilMask(0);
|
58
|
mRenderer.getScreen().attach(objectNode);
|
59
|
|
60
|
if( mShowStars )
|
61
|
{
|
62
|
mShowStars = false;
|
63
|
RubikScores scores = RubikScores.getInstance();
|
64
|
int totStars = scores.getNumStars();
|
65
|
DistortedScreen screen = mRenderer.getScreen();
|
66
|
OverlayStars stars = new OverlayStars();
|
67
|
DataStars data = new DataStars(totStars,0,getResources());
|
68
|
stars.startOverlay(screen,null,data);
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
|
73
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74
|
|
75
|
void setShowStars()
|
76
|
{
|
77
|
mShowStars = true;
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
boolean isVertical()
|
83
|
{
|
84
|
return mScreenHeight>mScreenWidth;
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
RubikRenderer getRenderer()
|
90
|
{
|
91
|
return mRenderer;
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
OSInterface getInterface()
|
97
|
{
|
98
|
return mInterface;
|
99
|
}
|
100
|
|
101
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
|
103
|
ObjectControl getObjectControl()
|
104
|
{
|
105
|
return mObjectController;
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
// PUBLIC API
|
110
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111
|
|
112
|
public RubikSurfaceView(Context context, AttributeSet attrs)
|
113
|
{
|
114
|
super(context,attrs);
|
115
|
|
116
|
mCreated = false;
|
117
|
mShowStars = false;
|
118
|
|
119
|
if(!isInEditMode())
|
120
|
{
|
121
|
RubikActivity act = (RubikActivity)context;
|
122
|
RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
|
123
|
mInterface = new OSInterface(act,ref);
|
124
|
mObjectController = new ObjectControl(mInterface);
|
125
|
mRenderer = new RubikRenderer(this);
|
126
|
|
127
|
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
128
|
|
129
|
try
|
130
|
{
|
131
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
132
|
int esVersion = configurationInfo.reqGlEsVersion>>16;
|
133
|
setEGLContextClientVersion(esVersion);
|
134
|
setRenderer(mRenderer);
|
135
|
}
|
136
|
catch(Exception ex)
|
137
|
{
|
138
|
act.OpenGLError();
|
139
|
|
140
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
141
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
142
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
143
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
144
|
|
145
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
146
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
147
|
crashlytics.setCustomKey("GL version" , version );
|
148
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
149
|
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
150
|
crashlytics.recordException(ex);
|
151
|
}
|
152
|
}
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
|
157
|
@Override
|
158
|
public void onPause()
|
159
|
{
|
160
|
super.onPause();
|
161
|
mObjectController.onPause();
|
162
|
}
|
163
|
|
164
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165
|
|
166
|
@Override
|
167
|
public void onResume()
|
168
|
{
|
169
|
super.onResume();
|
170
|
mObjectController.onResume();
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
@SuppressLint("ClickableViewAccessibility")
|
176
|
@Override
|
177
|
public boolean onTouchEvent(MotionEvent event)
|
178
|
{
|
179
|
mInterface.setMotionEvent(event);
|
180
|
int mode = ScreenList.getMode();
|
181
|
return mObjectController.onTouchEvent(mode);
|
182
|
}
|
183
|
}
|
184
|
|