add sounds

This commit is contained in:
Artem Budarin 2018-08-13 13:16:06 +05:00
parent fe73d7bec9
commit 26b6632158
13 changed files with 123 additions and 21 deletions

BIN
.DS_Store vendored

Binary file not shown.

35
jni/Sounds.cpp Executable file
View File

@ -0,0 +1,35 @@
#include "Sounds.h"
#include <jni.h>
static JNIEnv* env = NULL;
static jclass jSounds = NULL;
/** BackgroundSound */
void playBackgroundSound() {
jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayBackgroundSound", "()V");
env->CallStaticVoidMethod(jSounds, method);
}
void stopBackgroundSound () {
jmethodID method = env->GetStaticMethodID(jSounds, "JniStopBackgroundSound", "()V");
env->CallStaticVoidMethod(jSounds, method);
}
/** GameSound - Gunshot */
void playGameSoundGunshot() {
jmethodID method = env->GetStaticMethodID(jSounds, "JniPlayGunshotSound", "()V");
env->CallStaticVoidMethod(jSounds, method);
}
void stopGameSoundGunshot() {
jmethodID method = env->GetStaticMethodID(jSounds, "JniStopGunshotSound", "()V");
env->CallStaticVoidMethod(jSounds, method);
}
JNIEXPORT void JNICALL Java_com_fishrungames_crystalofrhylil_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis) {
env = pEnv;
jSounds = env->FindClass("com/fishrungames/crystalofrhyli/sounds/JniSoundCalls");
playBackgroundSound();
}

7
jni/Sounds.h Executable file
View File

@ -0,0 +1,7 @@
#include <jni.h>
extern "C" {
JNIEXPORT void JNICALL Java_com_fishrungames_crystalofrhylil_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis);
}

View File

@ -74,27 +74,27 @@ void TMyApplication::InnerInit()
*SE::Console << "APP INIT\n"; *SE::Console << "APP INIT\n";
} }
SE::ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex.txt", "shader1fragment.txt"); SE::ResourceManager->ShaderManager.AddShader("DefaultShader", "shader_vertex.txt", "shader_fragment.txt");
SE::ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt"); SE::ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt");
SE::ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt"); SE::ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt");
SE::Renderer->PushShader("DefaultShader"); SE::Renderer->PushShader("DefaultShader");
const std::string CONST_LOADING_BACKGROUND_BLACK = "loading_background_black"; const std::string CONST_LOADING_BACKGROUND_BLACK = "loading_background_black";
const std::string CONST_LOADING_TEXTURE = "loading"; const std::string CONST_LOADING_TEXTURE = "loading";
const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small"; const std::string CONST_LOGO_SMALL_TEXTURE = "logo_small";
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK); SE::ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK);
SE::ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE); SE::ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE);
SE::ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE); SE::ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE);
SE::ResourceManager->TexList.AddTexture("console_bkg.bmp"); SE::ResourceManager->TexList.AddTexture("console_bkg.bmp");
SE::ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512); SE::ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 512, 512);
Inited = true; Inited = true;
SE::Renderer->SetOrthoProjection(); SE::Renderer->SetOrthoProjection();
SE::Renderer->SetFullScreenViewport(); SE::Renderer->SetFullScreenViewport();

View File

@ -60,6 +60,8 @@ add_library( # Sets the name of the library.
${JNI_PATH}/main_code.cpp ${JNI_PATH}/main_code.cpp
${JNI_PATH}/match3/match3field.cpp ${JNI_PATH}/match3/match3field.cpp
${JNI_PATH}/android_api.cpp ${JNI_PATH}/android_api.cpp
${JNI_PATH}/Sounds.cpp
) )
add_library( engine add_library( engine

View File

@ -5,6 +5,8 @@ import java.util.Calendar;
import android.content.Context; import android.content.Context;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import com.fishrungames.crystalofrhylil.sounds.JniSoundCalls;
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
@ -58,6 +60,7 @@ class GLView extends GLViewAncestor
public void onSurfaceChanged(GL10 gl, int width, int height) public void onSurfaceChanged(GL10 gl, int width, int height)
{ {
JniWrapper.Init(width,height); JniWrapper.Init(width,height);
JniSoundCalls.init();
} }
public void onSurfaceCreated(GL10 gl, EGLConfig config) public void onSurfaceCreated(GL10 gl, EGLConfig config)

View File

@ -21,6 +21,8 @@ import android.view.MotionEvent;
public class MainActivity extends Activity public class MainActivity extends Activity
{ {
private static MainActivity instance;
GLView mView; GLView mView;
@Override @Override
@ -29,6 +31,8 @@ public class MainActivity extends Activity
super.onCreate(icicle); super.onCreate(icicle);
instance = this;
EngineWrapper.LoadSalmonEngineLibrary(); EngineWrapper.LoadSalmonEngineLibrary();
EngineWrapper.SetActivityInstance(this); EngineWrapper.SetActivityInstance(this);
EngineWrapper.SetupEnviroment(); EngineWrapper.SetupEnviroment();
@ -88,6 +92,14 @@ public class MainActivity extends Activity
EngineWrapper.ProcessKeyDown(keyCode, event); EngineWrapper.ProcessKeyDown(keyCode, event);
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public static MainActivity getInstance() {
if (instance == null) {
throw new RuntimeException("error GL2JNIActivity getInstance() - you are trying to get activity instance when it is not created or already destroyed");
}
return instance;
}
} }
//package com.fishrungames.crystalofrhylil; //package com.fishrungames.crystalofrhylil;

View File

@ -0,0 +1,43 @@
package com.fishrungames.crystalofrhylil.sounds;
import android.media.MediaPlayer;
import com.fishrungames.crystalofrhylil.MainActivity;
import com.fishrungames.crystalofrhylil.R;
public class JniSoundCalls {
native public static void initJniSounds();
private static MediaPlayer backgroundPlayer = null;
private static MediaPlayer gunshotPlayer = null;
public static void init() {
initJniSounds();
}
public static void JniPlayBackgroundSound() {
backgroundPlayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.background_sound);
backgroundPlayer.setLooping(true);
backgroundPlayer.start();
}
public static void JniStopBackgroundSound() {
if (backgroundPlayer != null) {
backgroundPlayer.stop();
}
}
public static void JniPlayGunshotSound() {
gunshotPlayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.gunshot_sound);
gunshotPlayer.setLooping(false);
gunshotPlayer.start();
}
public static void JniStopGunshotSound() {
if (gunshotPlayer != null) {
gunshotPlayer.stop();
}
}
}

Binary file not shown.

BIN
src/.DS_Store vendored Normal file

Binary file not shown.

BIN
src/fishrungames/.DS_Store vendored Normal file

Binary file not shown.