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.purchase;
|
11
|
|
12
|
import android.app.ActivityManager;
|
13
|
import android.content.Context;
|
14
|
import android.content.pm.ConfigurationInfo;
|
15
|
import android.content.res.Resources;
|
16
|
import android.opengl.GLSurfaceView;
|
17
|
|
18
|
import org.distorted.library.effect.EffectType;
|
19
|
import org.distorted.library.effect.VertexEffectQuaternion;
|
20
|
import org.distorted.library.effect.VertexEffectRotate;
|
21
|
import org.distorted.library.main.DistortedLibrary;
|
22
|
import org.distorted.library.main.DistortedScreen;
|
23
|
import org.distorted.library.mesh.MeshBase;
|
24
|
import org.distorted.objectlib.effects.BaseEffect;
|
25
|
import org.distorted.objectlib.main.ObjectControl;
|
26
|
import org.distorted.overlays.OverlayGeneric;
|
27
|
|
28
|
import java.io.InputStream;
|
29
|
|
30
|
import javax.microedition.khronos.egl.EGLConfig;
|
31
|
import javax.microedition.khronos.opengles.GL10;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class PurchaseRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
36
|
{
|
37
|
private static final int NUM_SCRAMBLES = 5;
|
38
|
private static final int DURATION = NUM_SCRAMBLES*2*1000;
|
39
|
|
40
|
private final PurchaseSurfaceView mView;
|
41
|
private final Resources mResources;
|
42
|
private final DistortedScreen mScreen;
|
43
|
|
44
|
private boolean mFirstRender;
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
PurchaseRenderer(PurchaseSurfaceView v)
|
49
|
{
|
50
|
final float BRIGHTNESS = 0.333f;
|
51
|
|
52
|
mView = v;
|
53
|
mResources = v.getResources();
|
54
|
|
55
|
mFirstRender = true;
|
56
|
mScreen = new DistortedScreen();
|
57
|
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
|
58
|
}
|
59
|
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
|
62
|
@Override
|
63
|
public void onDrawFrame(GL10 glUnused)
|
64
|
{
|
65
|
long time = System.currentTimeMillis();
|
66
|
mView.getObjectControl().preRender();
|
67
|
mScreen.render(time);
|
68
|
|
69
|
if( mFirstRender )
|
70
|
{
|
71
|
mFirstRender=false;
|
72
|
mView.getObjectControl().presentObject(NUM_SCRAMBLES, DURATION);
|
73
|
}
|
74
|
}
|
75
|
|
76
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
77
|
|
78
|
@Override
|
79
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
80
|
{
|
81
|
mScreen.resize(width,height);
|
82
|
mView.setScreenSize(width,height);
|
83
|
}
|
84
|
|
85
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86
|
|
87
|
DistortedScreen getScreen()
|
88
|
{
|
89
|
return mScreen;
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
@Override
|
95
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
96
|
{
|
97
|
DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1);
|
98
|
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
|
99
|
|
100
|
VertexEffectRotate.enable();
|
101
|
VertexEffectQuaternion.enable();
|
102
|
BaseEffect.Type.enableEffects();
|
103
|
OverlayGeneric.enableEffects();
|
104
|
|
105
|
DistortedLibrary.onSurfaceCreated(this,1);
|
106
|
DistortedLibrary.setCull(true);
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
public void distortedException(Exception ex)
|
112
|
{
|
113
|
android.util.Log.e("Purchase", "unexpected exception: "+ex.getMessage() );
|
114
|
}
|
115
|
|
116
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117
|
|
118
|
public InputStream localFile(int fileID)
|
119
|
{
|
120
|
return mResources.openRawResource(fileID);
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
public void logMessage(String message)
|
126
|
{
|
127
|
android.util.Log.e("Purchase", message );
|
128
|
}
|
129
|
}
|