diff --git a/app/build.gradle b/app/build.gradle index 5d52c5c..20a36d6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,8 +48,8 @@ android { applicationId "app.jerboa.spp" minSdk 23 targetSdk 34 - versionCode 43 - versionName "0.6.0" + versionCode 44 + versionName "0.6.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/app/jerboa/spp/MainActivity.kt b/app/src/main/java/app/jerboa/spp/MainActivity.kt index c98c2d2..5e2a90a 100644 --- a/app/src/main/java/app/jerboa/spp/MainActivity.kt +++ b/app/src/main/java/app/jerboa/spp/MainActivity.kt @@ -16,10 +16,10 @@ import android.widget.Toast import androidx.activity.compose.setContent import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity -import app.jerboa.spp.ViewModel.MUSIC -import app.jerboa.spp.ViewModel.REVIEW_RATE_LIMIT_MILLIS -import app.jerboa.spp.ViewModel.RenderViewModel -import app.jerboa.spp.ViewModel.SOCIAL +import app.jerboa.spp.viewmodel.MUSIC +import app.jerboa.spp.viewmodel.REVIEW_RATE_LIMIT_MILLIS +import app.jerboa.spp.viewmodel.RenderViewModel +import app.jerboa.spp.viewmodel.SOCIAL import app.jerboa.spp.composable.renderScreen import app.jerboa.spp.ui.theme.SPPTheme import com.google.android.gms.common.ConnectionResult diff --git a/app/src/main/java/app/jerboa/spp/composable/about.kt b/app/src/main/java/app/jerboa/spp/composable/about.kt index 9add5ba..0fa1604 100644 --- a/app/src/main/java/app/jerboa/spp/composable/about.kt +++ b/app/src/main/java/app/jerboa/spp/composable/about.kt @@ -21,7 +21,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import app.jerboa.spp.AppInfo import app.jerboa.spp.R -import app.jerboa.spp.ViewModel.SOCIAL +import app.jerboa.spp.viewmodel.SOCIAL @OptIn(ExperimentalAnimationApi::class) @Composable diff --git a/app/src/main/java/app/jerboa/spp/composable/colourMapMenu.kt b/app/src/main/java/app/jerboa/spp/composable/colourMapMenu.kt index 4f2c600..ec9c390 100644 --- a/app/src/main/java/app/jerboa/spp/composable/colourMapMenu.kt +++ b/app/src/main/java/app/jerboa/spp/composable/colourMapMenu.kt @@ -9,7 +9,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp -import app.jerboa.spp.ViewModel.COLOUR_MAP +import app.jerboa.spp.viewmodel.COLOUR_MAP @Composable fun colourMapMenu( diff --git a/app/src/main/java/app/jerboa/spp/composable/mainMenu.kt b/app/src/main/java/app/jerboa/spp/composable/mainMenu.kt index 4f54e7d..09518e0 100644 --- a/app/src/main/java/app/jerboa/spp/composable/mainMenu.kt +++ b/app/src/main/java/app/jerboa/spp/composable/mainMenu.kt @@ -23,21 +23,21 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import app.jerboa.spp.AppInfo -import app.jerboa.spp.ViewModel.COLOUR_MAP -import app.jerboa.spp.ViewModel.MAX_LOG_AR -import app.jerboa.spp.ViewModel.MAX_LOG_FADE -import app.jerboa.spp.ViewModel.MAX_LOG_MASS -import app.jerboa.spp.ViewModel.MAX_LOG_ORBIT -import app.jerboa.spp.ViewModel.MAX_LOG_SPEED -import app.jerboa.spp.ViewModel.MAX_LOG_SPIN -import app.jerboa.spp.ViewModel.MAX_PARTICLES -import app.jerboa.spp.ViewModel.MIN_LOG_AR -import app.jerboa.spp.ViewModel.MIN_LOG_FADE -import app.jerboa.spp.ViewModel.MIN_LOG_MASS -import app.jerboa.spp.ViewModel.MIN_LOG_ORBIT -import app.jerboa.spp.ViewModel.MIN_LOG_SPIN -import app.jerboa.spp.ViewModel.PARAM -import app.jerboa.spp.ViewModel.TOY +import app.jerboa.spp.viewmodel.COLOUR_MAP +import app.jerboa.spp.viewmodel.MAX_LOG_AR +import app.jerboa.spp.viewmodel.MAX_LOG_FADE +import app.jerboa.spp.viewmodel.MAX_LOG_MASS +import app.jerboa.spp.viewmodel.MAX_LOG_ORBIT +import app.jerboa.spp.viewmodel.MAX_LOG_SPEED +import app.jerboa.spp.viewmodel.MAX_LOG_SPIN +import app.jerboa.spp.viewmodel.MAX_PARTICLES +import app.jerboa.spp.viewmodel.MIN_LOG_AR +import app.jerboa.spp.viewmodel.MIN_LOG_FADE +import app.jerboa.spp.viewmodel.MIN_LOG_MASS +import app.jerboa.spp.viewmodel.MIN_LOG_ORBIT +import app.jerboa.spp.viewmodel.MIN_LOG_SPIN +import app.jerboa.spp.viewmodel.PARAM +import app.jerboa.spp.viewmodel.TOY import kotlin.math.ceil import kotlin.math.log10 import kotlin.math.pow diff --git a/app/src/main/java/app/jerboa/spp/composable/menuPrompt.kt b/app/src/main/java/app/jerboa/spp/composable/menuPrompt.kt index cfa719a..1b2c1ef 100644 --- a/app/src/main/java/app/jerboa/spp/composable/menuPrompt.kt +++ b/app/src/main/java/app/jerboa/spp/composable/menuPrompt.kt @@ -8,7 +8,6 @@ import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.foundation.Image -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* @@ -17,10 +16,9 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha -import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp -import app.jerboa.spp.ViewModel.MUSIC +import app.jerboa.spp.viewmodel.MUSIC @OptIn(ExperimentalAnimationApi::class) @Composable diff --git a/app/src/main/java/app/jerboa/spp/composable/renderScreen.kt b/app/src/main/java/app/jerboa/spp/composable/renderScreen.kt index 1334ac9..04a1cab 100644 --- a/app/src/main/java/app/jerboa/spp/composable/renderScreen.kt +++ b/app/src/main/java/app/jerboa/spp/composable/renderScreen.kt @@ -1,6 +1,5 @@ package app.jerboa.spp.composable -import android.util.Log import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.fillMaxWidth @@ -11,7 +10,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import app.jerboa.spp.AppInfo -import app.jerboa.spp.ViewModel.* +import app.jerboa.spp.viewmodel.* @Composable fun renderScreen( diff --git a/app/src/main/java/app/jerboa/spp/composable/screen.kt b/app/src/main/java/app/jerboa/spp/composable/screen.kt index bb1853b..0a99ae3 100644 --- a/app/src/main/java/app/jerboa/spp/composable/screen.kt +++ b/app/src/main/java/app/jerboa/spp/composable/screen.kt @@ -1,22 +1,19 @@ package app.jerboa.spp.composable import android.annotation.SuppressLint -import android.util.Log import androidx.compose.animation.* import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.viewinterop.AndroidView -import androidx.lifecycle.MutableLiveData import app.jerboa.spp.AppInfo -import app.jerboa.spp.ViewModel.COLOUR_MAP -import app.jerboa.spp.ViewModel.MUSIC -import app.jerboa.spp.ViewModel.PARAM -import app.jerboa.spp.ViewModel.SOCIAL -import app.jerboa.spp.ViewModel.TOY -import app.jerboa.spp.data.ColourMap -import app.jerboa.spp.ui.SPPView +import app.jerboa.spp.viewmodel.COLOUR_MAP +import app.jerboa.spp.viewmodel.MUSIC +import app.jerboa.spp.viewmodel.PARAM +import app.jerboa.spp.viewmodel.SOCIAL +import app.jerboa.spp.viewmodel.TOY +import app.jerboa.spp.ui.view.SPPView import kotlinx.coroutines.launch @OptIn(ExperimentalAnimationApi::class) diff --git a/app/src/main/java/app/jerboa/spp/composable/socials.kt b/app/src/main/java/app/jerboa/spp/composable/socials.kt index f837b6a..3e60a68 100644 --- a/app/src/main/java/app/jerboa/spp/composable/socials.kt +++ b/app/src/main/java/app/jerboa/spp/composable/socials.kt @@ -17,7 +17,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import app.jerboa.spp.AppInfo import app.jerboa.spp.R -import app.jerboa.spp.ViewModel.SOCIAL +import app.jerboa.spp.viewmodel.SOCIAL @Composable fun socials( diff --git a/app/src/main/java/app/jerboa/spp/data/Shader.kt b/app/src/main/java/app/jerboa/spp/data/Shader.kt index 4de5ad7..81cc65a 100644 --- a/app/src/main/java/app/jerboa/spp/data/Shader.kt +++ b/app/src/main/java/app/jerboa/spp/data/Shader.kt @@ -2,7 +2,7 @@ package app.jerboa.spp.data import android.opengl.GLES31 import android.util.Log -import app.jerboa.glskeleton.utils.compileGLSLProgram +import app.jerboa.spp.utils.compileGLSLProgram import java.nio.ByteBuffer import java.nio.ByteOrder diff --git a/app/src/main/java/app/jerboa/spp/data/ShaderData.kt b/app/src/main/java/app/jerboa/spp/data/ShaderData.kt index f163a25..a458b4e 100644 --- a/app/src/main/java/app/jerboa/spp/data/ShaderData.kt +++ b/app/src/main/java/app/jerboa/spp/data/ShaderData.kt @@ -1,11 +1,5 @@ package app.jerboa.spp.data -import android.util.Log -import app.jerboa.glskeleton.utils.compileGLSLProgram -import java.nio.ByteBuffer -import java.nio.ByteOrder -import android.opengl.GLES31 as gl3 - abstract class ShaderData(open val vertexShader: String, open val fragmentShader: String) class Mat4( val elements: FloatArray = FloatArray(16){0f} diff --git a/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt b/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt index e5f2b43..f367970 100644 --- a/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt +++ b/app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt @@ -5,8 +5,7 @@ import android.opengl.GLES31.* import android.opengl.GLSurfaceView import android.opengl.Matrix import android.util.Log -import app.jerboa.glskeleton.utils.* -import app.jerboa.spp.ViewModel.* +import app.jerboa.spp.viewmodel.* import app.jerboa.spp.data.* import app.jerboa.spp.utils.* import kotlinx.coroutines.CoroutineScope @@ -26,7 +25,7 @@ import android.opengl.GLES31 as gl3 const val DEBUG: Boolean = false const val PERFORMANCE: Boolean = false -enum class DRAG_ACTION {START, STOP, CONTINUE} +enum class DRAG {START, STOP, CONTINUE} class SPPRenderer( private val resolution: Pair, @@ -375,14 +374,14 @@ class SPPRenderer( } // drag event - fun drag(x: Float, y: Float, state: DRAG_ACTION, toyType: TOY){ + fun drag(x: Float, y: Float, state: DRAG, toyType: TOY){ if (DEMO_REAL){return} val w = screenToWorld(x,resolution.second-y) val wx = w[0] val wy = w[1] when (state){ - DRAG_ACTION.START -> { + DRAG.START -> { dragStartTime = System.currentTimeMillis() val toy = toySelected(wx, wy) if (toy != null){ @@ -438,7 +437,7 @@ class SPPRenderer( } dragDelta = Vec2(0f,0f) } - DRAG_ACTION.STOP -> { + DRAG.STOP -> { draggedToy = null if (dragPlacedToy){dragPlacedToy = false; return} @@ -452,7 +451,7 @@ class SPPRenderer( } } - DRAG_ACTION.CONTINUE -> { + DRAG.CONTINUE -> { var dx: Float = 0f var dy: Float = 0f val toy = draggedToy @@ -644,8 +643,8 @@ class SPPRenderer( particleDrawShader.fragmentShader = ParticleDrawShaderData().fragmentShader + particleDrawShader.release() particleDrawShader.compile() - particleDrawShader.use() // now we add a few uniforms that don't need to be updated @@ -661,7 +660,9 @@ class SPPRenderer( particleDrawShader.setUniform("scale",scale) particleDrawShader.setUniform("transitionSteps",transitionSteps) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } } @@ -823,7 +824,9 @@ class SPPRenderer( val qTex = texBuffer[Textures[TextureId.Y]!!] val paramTex = texBuffer[Textures[TextureId.PARAM]!!] - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // instance and pack each texture @@ -833,12 +836,16 @@ class SPPRenderer( initTexture2DRGBA32F(pTex, m) transferToTexture2DRGBA32F(pTex, particleBuffer, m) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } initTexture2DRGBA32F(qTex, m) transferToTexture2DRGBA32F(qTex, qBuffer, m) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } initTexture2DRGBA32F(paramTex,m) transferToTexture2DRGBA32F(paramTex,pBuffer,m) @@ -850,7 +857,9 @@ class SPPRenderer( compileDrawShader() - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } computeShader.release() computeShader.compile() @@ -908,7 +917,9 @@ class SPPRenderer( fadeShader.release() fadeShader.compile() - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } gl3.glGenQueries(1,queryBuffer) } @@ -1061,7 +1072,9 @@ class SPPRenderer( demoFrameId += 1 } - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } val pTex = texBuffer[Textures[TextureId.X]!!] val qTex = texBuffer[Textures[TextureId.Y]!!] @@ -1137,7 +1150,9 @@ class SPPRenderer( particleDrawShader.setUniform("n",m) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // instanced drawing of p particles @@ -1156,7 +1171,9 @@ class SPPRenderer( allParticlesOfScreen = true } } - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } } private fun drawToys() { @@ -1229,15 +1246,21 @@ class SPPRenderer( toyDrawShader.setUniform("alpha",toysAlpha) } - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } gl3.glEnableVertexAttribArray(0) gl3.glVertexAttribPointer(0, 3, gl3.GL_FLOAT, false, 0, drawVertices) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // draw the toys gl3.glDrawArraysInstanced(gl3.GL_POINTS, 0, 1, 40) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } } private fun step(delta: Float){ @@ -1250,14 +1273,18 @@ class SPPRenderer( val m = ceil(sqrt(p.toFloat())).toInt() - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // gen frame buffer which we will "draw" particle positions to fbos.clear() gl3.glGenFramebuffers(1,fbos) val fbo = fbos[0] gl3.glBindFramebuffer(gl3.GL_FRAMEBUFFER, fbo) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // frame buffer textures // position now @@ -1285,7 +1312,9 @@ class SPPRenderer( 0 ) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } glBufferStatus() // pTex and qTex need to be dranw too, paramTex is constant for now @@ -1295,7 +1324,9 @@ class SPPRenderer( drawBuffers.flip() drawBuffers.limit(2) gl3.glDrawBuffers(2,drawBuffers) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } glBufferStatus() gl3.glActiveTexture(gl3.GL_TEXTURE2) @@ -1371,22 +1402,30 @@ class SPPRenderer( gl3.glViewport(0, 0, m, m) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // upload the vertices into attribute 0 (see shaders) gl3.glEnableVertexAttribArray(0) gl3.glVertexAttribPointer(0, 3, gl3.GL_FLOAT, false, 0, computeVerts) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // textures go ini attribute 1 gl3.glEnableVertexAttribArray(1) gl3.glVertexAttribPointer(1, 2, gl3.GL_FLOAT, false, 0, computeTexCoords) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // draw the quad === compute the next positions gl3.glDrawArrays(gl3.GL_TRIANGLES, 0, 6) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // if needed we can retrieve and print particle positions while developing // this of course crushes performance @@ -1399,7 +1438,9 @@ class SPPRenderer( returnBuffer.limit(4 * m * m) glBufferStatus() - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // get all pixels in the return buffer gl3.glReadPixels( 0, @@ -1412,7 +1453,9 @@ class SPPRenderer( ) returnBuffer.flip() returnBuffer.limit(4 * m * m) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } glBufferStatus() // get result as float array @@ -1430,7 +1473,9 @@ class SPPRenderer( returnBuffer.limit(4 * m * m) glBufferStatus() - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } // get all pixels in the return buffer gl3.glReadPixels( 0, @@ -1443,7 +1488,9 @@ class SPPRenderer( ) returnBuffer.flip() returnBuffer.limit(4 * m * m) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } glBufferStatus() // get result as float array @@ -1462,7 +1509,9 @@ class SPPRenderer( drawBuffers.flip() drawBuffers.limit(2) gl3.glDeleteBuffers(2,drawBuffers) - if (DEBUG_GL){glError()} + if (DEBUG_GL){ + glError() + } } private fun achievements(){ diff --git a/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt b/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt index de41bbd..7ba7879 100644 --- a/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt +++ b/app/src/main/java/app/jerboa/spp/ui/view/SPPView.kt @@ -1,19 +1,14 @@ -package app.jerboa.spp.ui +package app.jerboa.spp.ui.view import android.content.Context import android.opengl.GLSurfaceView import android.util.AttributeSet -import android.util.Log -import android.view.DragEvent import android.view.GestureDetector import android.view.MotionEvent import androidx.core.view.GestureDetectorCompat -import androidx.core.view.MotionEventCompat -import app.jerboa.spp.ViewModel.COLOUR_MAP -import app.jerboa.spp.ViewModel.PARTICLES_SLIDER_DEFAULT -import app.jerboa.spp.ViewModel.TOY -import app.jerboa.spp.ui.view.DRAG_ACTION -import app.jerboa.spp.ui.view.SPPRenderer +import app.jerboa.spp.viewmodel.COLOUR_MAP +import app.jerboa.spp.viewmodel.PARTICLES_SLIDER_DEFAULT +import app.jerboa.spp.viewmodel.TOY class SPPView ( context: Context, @@ -101,7 +96,7 @@ class SPPView ( lastTouchX = event.getX(pointer) lastTouchY = event.getY(pointer) } - renderer.drag(lastTouchX,lastTouchY,DRAG_ACTION.START, placingToy) + renderer.drag(lastTouchX,lastTouchY,DRAG.START, placingToy) pointerId = event.getPointerId(0) } MotionEvent.ACTION_MOVE -> { @@ -120,12 +115,12 @@ class SPPView ( lastTouchX = x lastTouchY = y - renderer.drag(x, y, DRAG_ACTION.CONTINUE, placingToy) + renderer.drag(x, y, DRAG.CONTINUE, placingToy) } } MotionEvent.ACTION_UP -> { pointerId = MotionEvent.INVALID_POINTER_ID - renderer.drag(lastTouchX,lastTouchY,DRAG_ACTION.STOP, placingToy) + renderer.drag(lastTouchX,lastTouchY,DRAG.STOP, placingToy) } MotionEvent.ACTION_POINTER_UP -> { event.actionIndex.also { pointer -> @@ -134,7 +129,7 @@ class SPPView ( val newPointerIndex = if (pointer == 0) 1 else 0 lastTouchX = event.getX(newPointerIndex) lastTouchY = event.getY(newPointerIndex) - renderer.drag(lastTouchX,lastTouchY,DRAG_ACTION.STOP, placingToy) + renderer.drag(lastTouchX,lastTouchY,DRAG.STOP, placingToy) } } } diff --git a/app/src/main/java/app/jerboa/spp/utils/glUtils.kt b/app/src/main/java/app/jerboa/spp/utils/glUtils.kt index 7ca338c..483282a 100644 --- a/app/src/main/java/app/jerboa/spp/utils/glUtils.kt +++ b/app/src/main/java/app/jerboa/spp/utils/glUtils.kt @@ -1,4 +1,4 @@ -package app.jerboa.glskeleton.utils +package app.jerboa.spp.utils import android.util.Log import java.nio.FloatBuffer import android.opengl.GLES30 as gl3 diff --git a/app/src/main/java/app/jerboa/spp/ViewModel/renderViewModel.kt b/app/src/main/java/app/jerboa/spp/viewmodel/renderViewModel.kt similarity index 99% rename from app/src/main/java/app/jerboa/spp/ViewModel/renderViewModel.kt rename to app/src/main/java/app/jerboa/spp/viewmodel/renderViewModel.kt index eb3881e..12642cb 100644 --- a/app/src/main/java/app/jerboa/spp/ViewModel/renderViewModel.kt +++ b/app/src/main/java/app/jerboa/spp/viewmodel/renderViewModel.kt @@ -1,4 +1,4 @@ -package app.jerboa.spp.ViewModel +package app.jerboa.spp.viewmodel import android.media.MediaPlayer import android.util.Log