Project

General

Profile

Download (6.07 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / main_old / RubikSurfaceView.java @ ab19c113

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_old;
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 boolean mCreated;
40
    private boolean mShowStars;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
    void setScreenSize(int width, int height)
45
      {
46
      mObjectController.setScreenSizeAndScaling(width,height, Math.min(width, (int)(0.75f*height)));
47

    
48
      if( !mCreated )
49
        {
50
        mCreated = true;
51
        mObjectController.createNode(width,height);
52
        TwistyObjectNode objectNode = mObjectController.getNode();
53
        objectNode.glDepthMask(false);
54
        objectNode.glStencilMask(0);
55
        mRenderer.getScreen().attach(objectNode);
56

    
57
        if( mShowStars )
58
          {
59
          mShowStars = false;
60
          RubikScores scores = RubikScores.getInstance();
61
          int totStars = scores.getNumStars();
62
          DistortedScreen screen = mRenderer.getScreen();
63
          OverlayStars stars = new OverlayStars();
64
          DataStars data = new DataStars(totStars,0,getResources());
65
          stars.startOverlay(screen,null,data);
66
          }
67
        }
68
      }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
    void setShowStars()
73
      {
74
      mShowStars = true;
75
      }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
    RubikRenderer getRenderer()
80
      {
81
      return mRenderer;
82
      }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
    OSInterface getInterface()
87
      {
88
      return mInterface;
89
      }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
    ObjectControl getObjectControl()
94
      {
95
      return mObjectController;
96
      }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
// PUBLIC API
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
    public RubikSurfaceView(Context context, AttributeSet attrs)
103
      {
104
      super(context,attrs);
105

    
106
      mCreated = false;
107
      mShowStars = false;
108

    
109
      if(!isInEditMode())
110
        {
111
        RubikActivity act = (RubikActivity)context;
112
        RubikObjectLibInterface ref = new RubikObjectLibInterface(act);
113
        mInterface = new OSInterface(act,ref);
114
        mObjectController = new ObjectControl(mInterface);
115
        mRenderer = new RubikRenderer(this);
116

    
117
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
118

    
119
        try
120
          {
121
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
122
          int esVersion = configurationInfo.reqGlEsVersion>>16;
123
          setEGLContextClientVersion(esVersion);
124
          setRenderer(mRenderer);
125
          }
126
        catch(Exception ex)
127
          {
128
          act.OpenGLError();
129

    
130
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
131
          String version = GLES30.glGetString(GLES30.GL_VERSION);
132
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
133
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
134

    
135
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
136
          crashlytics.setCustomKey("GLSL Version"  , shading );
137
          crashlytics.setCustomKey("GL version"    , version );
138
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
139
          crashlytics.setCustomKey("GLSL renderer" , renderer);
140
          crashlytics.recordException(ex);
141
          }
142
        }
143
      }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
    @Override
148
    public void onPause()
149
      {
150
      super.onPause();
151
      mObjectController.onPause();
152
      }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
    @Override
157
    public void onResume()
158
      {
159
      super.onResume();
160
      mObjectController.onResume();
161
      }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
    @SuppressLint("ClickableViewAccessibility")
166
    @Override
167
    public boolean onTouchEvent(MotionEvent event)
168
      {
169
      mInterface.setMotionEvent(event);
170
      int mode = ScreenList.getMode();
171
      return mObjectController.onTouchEvent(mode);
172
      }
173
}
174

    
(4-4/4)