| 1 |
cb30e768
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2023 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.solverui;
|
| 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.objectlib.main.ObjectControl;
|
| 24 |
|
|
import org.distorted.objectlib.main.TwistyObjectNode;
|
| 25 |
|
|
import org.distorted.os.OSInterface;
|
| 26 |
|
|
|
| 27 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 28 |
|
|
|
| 29 |
|
|
public class SolverSurfaceView extends GLSurfaceView
|
| 30 |
|
|
{
|
| 31 |
|
|
private ObjectControl mObjectController;
|
| 32 |
|
|
private OSInterface mInterface;
|
| 33 |
|
|
private SolverRenderer mRenderer;
|
| 34 |
|
|
private boolean mCreated;
|
| 35 |
|
|
|
| 36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 37 |
|
|
|
| 38 |
|
|
void setScreenSize(int width, int height)
|
| 39 |
|
|
{
|
| 40 |
|
|
mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)));
|
| 41 |
|
|
|
| 42 |
|
|
if( !mCreated )
|
| 43 |
|
|
{
|
| 44 |
|
|
mCreated = true;
|
| 45 |
|
|
mObjectController.createNode(width,height);
|
| 46 |
|
|
TwistyObjectNode objectNode = mObjectController.getNode();
|
| 47 |
|
|
objectNode.glDepthMask(false);
|
| 48 |
|
|
objectNode.glStencilMask(0);
|
| 49 |
|
|
mRenderer.getScreen().attach(objectNode);
|
| 50 |
|
|
}
|
| 51 |
|
|
}
|
| 52 |
|
|
|
| 53 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 54 |
|
|
|
| 55 |
|
|
SolverRenderer getRenderer()
|
| 56 |
|
|
{
|
| 57 |
|
|
return mRenderer;
|
| 58 |
|
|
}
|
| 59 |
|
|
|
| 60 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 61 |
|
|
|
| 62 |
|
|
OSInterface getInterface()
|
| 63 |
|
|
{
|
| 64 |
|
|
return mInterface;
|
| 65 |
|
|
}
|
| 66 |
|
|
|
| 67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 68 |
|
|
|
| 69 |
|
|
ObjectControl getObjectControl()
|
| 70 |
|
|
{
|
| 71 |
|
|
return mObjectController;
|
| 72 |
|
|
}
|
| 73 |
|
|
|
| 74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 75 |
|
|
// PUBLIC API
|
| 76 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 77 |
|
|
|
| 78 |
|
|
public SolverSurfaceView(Context context, AttributeSet attrs)
|
| 79 |
|
|
{
|
| 80 |
|
|
super(context,attrs);
|
| 81 |
|
|
|
| 82 |
|
|
mCreated = false;
|
| 83 |
|
|
|
| 84 |
|
|
if(!isInEditMode())
|
| 85 |
|
|
{
|
| 86 |
|
|
SolverActivity act = (SolverActivity)context;
|
| 87 |
|
|
SolverObjectLibInterface ref = new SolverObjectLibInterface(act);
|
| 88 |
|
|
mInterface = new OSInterface(act,ref);
|
| 89 |
|
|
mObjectController = new ObjectControl(mInterface);
|
| 90 |
|
|
mRenderer = new SolverRenderer(this);
|
| 91 |
|
|
|
| 92 |
|
|
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
| 93 |
|
|
|
| 94 |
|
|
try
|
| 95 |
|
|
{
|
| 96 |
|
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
| 97 |
|
|
int esVersion = configurationInfo.reqGlEsVersion>>16;
|
| 98 |
|
|
setEGLContextClientVersion(esVersion);
|
| 99 |
|
|
setRenderer(mRenderer);
|
| 100 |
|
|
}
|
| 101 |
|
|
catch(Exception ex)
|
| 102 |
|
|
{
|
| 103 |
|
|
act.OpenGLError();
|
| 104 |
|
|
|
| 105 |
|
|
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
|
| 106 |
|
|
String version = GLES30.glGetString(GLES30.GL_VERSION);
|
| 107 |
|
|
String vendor = GLES30.glGetString(GLES30.GL_VENDOR);
|
| 108 |
|
|
String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
|
| 109 |
|
|
|
| 110 |
|
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
| 111 |
|
|
crashlytics.setCustomKey("GLSL Version" , shading );
|
| 112 |
|
|
crashlytics.setCustomKey("GL version" , version );
|
| 113 |
|
|
crashlytics.setCustomKey("GL Vendor " , vendor );
|
| 114 |
|
|
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
| 115 |
|
|
crashlytics.recordException(ex);
|
| 116 |
|
|
}
|
| 117 |
|
|
}
|
| 118 |
|
|
}
|
| 119 |
|
|
|
| 120 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 121 |
|
|
|
| 122 |
|
|
@Override
|
| 123 |
|
|
public void onPause()
|
| 124 |
|
|
{
|
| 125 |
|
|
super.onPause();
|
| 126 |
|
|
mObjectController.onPause();
|
| 127 |
|
|
}
|
| 128 |
|
|
|
| 129 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 130 |
|
|
|
| 131 |
|
|
@Override
|
| 132 |
|
|
public void onResume()
|
| 133 |
|
|
{
|
| 134 |
|
|
super.onResume();
|
| 135 |
|
|
mObjectController.onResume();
|
| 136 |
|
|
}
|
| 137 |
|
|
|
| 138 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 139 |
|
|
|
| 140 |
|
|
@SuppressLint("ClickableViewAccessibility")
|
| 141 |
|
|
@Override
|
| 142 |
|
|
public boolean onTouchEvent(MotionEvent event)
|
| 143 |
|
|
{
|
| 144 |
|
|
mInterface.setMotionEvent(event);
|
| 145 |
|
|
int mode = ScreenList.getMode();
|
| 146 |
|
|
return mObjectController.onTouchEvent(mode);
|
| 147 |
|
|
}
|
| 148 |
|
|
}
|