This commit is contained in:
Ilshat Safiullin 2018-10-03 01:05:22 +05:00
commit c7290d0d0f
20 changed files with 393 additions and 87 deletions

34
game/Sounds.cpp Executable file
View File

@ -0,0 +1,34 @@
#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_fishrungames_doublehitballs_sounds_JniSoundCalls_initJniSounds(JNIEnv *pEnv, jobject pThis) {
env = pEnv;
jSounds = env->FindClass("fishrungames/doublehitballs/sounds/JniSoundCalls");
}

7
game/Sounds.h Executable file
View File

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

View File

@ -1,38 +1,15 @@
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.
cmake_minimum_required(VERSION 3.4.1) cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
add_definitions(-DTARGET_ANDROID)
set(BOOST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../boost_1_67_0) set(BOOST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../boost_1_67_0)
set(BOOST_GIL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/boost-gil-extension) set(BOOST_GIL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/boost-gil-extension)
set(ZIP_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/julienr-libzip-android/jni) set(ZIP_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/julienr-libzip-android/jni)
set(LIBPNG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libpng_1.4.1_android) set(LIBPNG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libpng_1.4.1_android)
set(LIBJPEG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/jpeg-9)
set(LIBJPEG_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/jpeg-9")
set(EIGEN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../eigen) set(EIGEN_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../eigen)
set(SOL2_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../sol2) set(SOL2_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../sol2)
set(LUA_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/lua-5.3.4/src) set(LUA_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/lua-5.3.4/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../tes-engine) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../tes-engine)
include_directories(${BOOST_PATH}) include_directories(${BOOST_PATH})
include_directories(${EIGEN_PATH}) include_directories(${EIGEN_PATH})
include_directories(${SOL2_PATH}) include_directories(${SOL2_PATH})
@ -40,34 +17,22 @@ include_directories(${LUA_PATH})
include_directories(${LIBPNG_PATH}) include_directories(${LIBPNG_PATH})
include_directories(${LIBJPEG_PATH}) include_directories(${LIBJPEG_PATH})
include_directories(${ZIP_PATH}) include_directories(${ZIP_PATH})
include_directories(${BOOST_GIL_PATH}) include_directories(${BOOST_GIL_PATH})
add_library( engine add_definitions(-DTARGET_ANDROID)
SHARED
IMPORTED )
set_target_properties( # Specifies the target library. add_library(engine SHARED IMPORTED
engine
# Specifies the parameter you want to define. )
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import. set_target_properties(engine PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/../../../tes-engine/SalmonEngineAndroid/app/build/intermediates/cmake/debug/obj/${ANDROID_ABI}/libengine.so )
${CMAKE_CURRENT_SOURCE_DIR}/../../../tes-engine/SalmonEngineAndroid/app/build/intermediates/cmake/debug/obj/${ANDROID_ABI}/libengine.so
)
add_library(DoubleHitBalls SHARED
add_library( # Sets the name of the library.
DoubleHitBalls
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
${CMAKE_CURRENT_SOURCE_DIR}/../../game/android_api.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/android_api.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../game/main_code.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/main_code.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../game/creditscode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/creditscode.cpp
@ -77,38 +42,20 @@ add_library( # Sets the name of the library.
${CMAKE_CURRENT_SOURCE_DIR}/../../game/gamecode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/gamecode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../game/loadingcode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/loadingcode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../game/menucode.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../game/menucode.cpp
) ${CMAKE_CURRENT_SOURCE_DIR}/../../game/Sounds.cpp
)
find_library(log-lib
log
)
# Searches for a specified prebuilt library and stores the path as a find_library(GLESv2-lib
# variable. Because system libraries are included in the search path by GLESv2
# default, you only need to specify the name of the public NDK library )
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable. target_link_libraries(DoubleHitBalls
log-lib engine
${log-lib}
# Specifies the name of the NDK library that ${GLESv2-lib}
# you want CMake to locate. )
log )
find_library( # Sets the name of the path variable.
GLESv2-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
GLESv2 )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
DoubleHitBalls
# Links the target library to the log library
# included in the NDK.
${log-lib} ${GLESv2-lib} engine )

View File

@ -21,6 +21,8 @@ import android.view.MotionEvent;
public class GL2JNIActivity extends Activity public class GL2JNIActivity extends Activity
{ {
private static GL2JNIActivity instance;
GLView mView; GLView mView;
@Override @Override
@ -29,6 +31,8 @@ public class GL2JNIActivity 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,4 +92,12 @@ public class GL2JNIActivity extends Activity
EngineWrapper.ProcessKeyDown(keyCode, event); EngineWrapper.ProcessKeyDown(keyCode, event);
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public static GL2JNIActivity 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;
}
} }

View File

@ -9,6 +9,7 @@ import android.opengl.GLSurfaceView;
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
import fishrungames.doublehitballs.sounds.JniSoundCalls;
import fishrungames.salmonengineandroid.GLViewAncestor; import fishrungames.salmonengineandroid.GLViewAncestor;
import fishrungames.salmonengineandroid.EngineWrapper; import fishrungames.salmonengineandroid.EngineWrapper;
@ -59,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

@ -6,7 +6,6 @@ public class JniWrapper
System.loadLibrary("DoubleHitBalls"); System.loadLibrary("DoubleHitBalls");
} }
public static native void Init(int width, int height); public static native void Init(int width, int height);
} }

View File

@ -0,0 +1,49 @@
package fishrungames.doublehitballs.sounds;
import android.media.MediaPlayer;
import fishrungames.doublehitballs.GL2JNIActivity;
import fishrungames.doublehitballs.R;
/**
* example sounds for JNI calls
* @author Artem Budarin
* Created by Artem Budarin on 06.08.2018.
*/
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(GL2JNIActivity.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(GL2JNIActivity.getInstance(), R.raw.gunshot_sound);
gunshotPlayer.setLooping(false);
gunshotPlayer.start();
}
public static void JniStopGunshotSound() {
if (gunshotPlayer != null) {
gunshotPlayer.stop();
}
}
}

Binary file not shown.

16
proj.ios/BridgeDelegate.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef BridgeDelegate_h
#define BridgeDelegate_h
class BridgeDelegate
{
public:
static void playBackgroundSound();
static void stopBackgroundSound();
static void playGunshotSound();
static void stopGunshotSound();
};
#endif /* BridgeDelegate_h */

View File

@ -0,0 +1,22 @@
#include "BridgeDelegate.h"
#import "Sounds.h"
void BridgeDelegate::playBackgroundSound()
{
[ShareSounds playBackgroundSound];
}
void BridgeDelegate::stopBackgroundSound()
{
[ShareSounds stopBackgroundSound];
}
void BridgeDelegate::playGunshotSound()
{
[ShareSounds playGunshotSound];
}
void BridgeDelegate::stopGunshotSound()
{
[ShareSounds stopGunshotSound];
}

View File

@ -32,6 +32,13 @@
84D0FEBE1E274DDD00EC3FE5 /* libSalmon Engine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C902A7815C5735700FBC901 /* libSalmon Engine.a */; }; 84D0FEBE1E274DDD00EC3FE5 /* libSalmon Engine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C902A7815C5735700FBC901 /* libSalmon Engine.a */; };
84D0FEC91E274E4A00EC3FE5 /* libvorbis-tremor-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D0FEC61E274E3700EC3FE5 /* libvorbis-tremor-ios.a */; }; 84D0FEC91E274E4A00EC3FE5 /* libvorbis-tremor-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D0FEC61E274E3700EC3FE5 /* libvorbis-tremor-ios.a */; };
84D0FECC1E274EBC00EC3FE5 /* main_code.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */; }; 84D0FECC1E274EBC00EC3FE5 /* main_code.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */; };
AC67C87D211C8DD3003AA164 /* NativeSoundCalls.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC67C87C211C8DD3003AA164 /* NativeSoundCalls.swift */; };
AC67C87F211C8DE3003AA164 /* NativeSoundCallsImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC67C87E211C8DE3003AA164 /* NativeSoundCallsImpl.swift */; };
AC67C882211C8E24003AA164 /* gunshot_sound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = AC67C880211C8E24003AA164 /* gunshot_sound.mp3 */; };
AC67C883211C8E24003AA164 /* background_sound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = AC67C881211C8E24003AA164 /* background_sound.mp3 */; };
AC8032262122F8B100DEA5AC /* SoundCalls.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC8032242122F8B100DEA5AC /* SoundCalls.cpp */; };
AC80322A2122F8DD00DEA5AC /* BridgeDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC8032282122F8DC00DEA5AC /* BridgeDelegate.mm */; };
ACC6F8382121E8DF00CEDC5C /* Sounds.m in Sources */ = {isa = PBXBuildFile; fileRef = ACC6F8372121E8DF00CEDC5C /* Sounds.m */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@ -103,6 +110,16 @@
84D0FEC11E274E3700EC3FE5 /* vorbis-tremor-ios.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "vorbis-tremor-ios.xcodeproj"; path = "../../libs/vorbis-tremor-ios/vorbis-tremor-ios.xcodeproj"; sourceTree = "<group>"; }; 84D0FEC11E274E3700EC3FE5 /* vorbis-tremor-ios.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "vorbis-tremor-ios.xcodeproj"; path = "../../libs/vorbis-tremor-ios/vorbis-tremor-ios.xcodeproj"; sourceTree = "<group>"; };
84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main_code.cpp; path = ../game/main_code.cpp; sourceTree = "<group>"; }; 84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main_code.cpp; path = ../game/main_code.cpp; sourceTree = "<group>"; };
84D0FECB1E274EBC00EC3FE5 /* main_code.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = main_code.h; path = ../game/main_code.h; sourceTree = "<group>"; }; 84D0FECB1E274EBC00EC3FE5 /* main_code.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = main_code.h; path = ../game/main_code.h; sourceTree = "<group>"; };
AC67C87C211C8DD3003AA164 /* NativeSoundCalls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSoundCalls.swift; sourceTree = "<group>"; };
AC67C87E211C8DE3003AA164 /* NativeSoundCallsImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSoundCallsImpl.swift; sourceTree = "<group>"; };
AC67C880211C8E24003AA164 /* gunshot_sound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = gunshot_sound.mp3; sourceTree = "<group>"; };
AC67C881211C8E24003AA164 /* background_sound.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = background_sound.mp3; sourceTree = "<group>"; };
AC8032242122F8B100DEA5AC /* SoundCalls.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SoundCalls.cpp; sourceTree = "<group>"; };
AC8032282122F8DC00DEA5AC /* BridgeDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BridgeDelegate.mm; sourceTree = "<group>"; };
AC8032292122F8DD00DEA5AC /* BridgeDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BridgeDelegate.h; sourceTree = "<group>"; };
AC80322B2122FBC100DEA5AC /* SoundCalls.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SoundCalls.h; sourceTree = "<group>"; };
ACC6F8372121E8DF00CEDC5C /* Sounds.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Sounds.m; sourceTree = "<group>"; };
ACC6F8392121E8ED00CEDC5C /* Sounds.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Sounds.h; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -128,6 +145,8 @@
4C49B2AE15B0991B003512CD = { 4C49B2AE15B0991B003512CD = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
AC67C881211C8E24003AA164 /* background_sound.mp3 */,
AC67C880211C8E24003AA164 /* gunshot_sound.mp3 */,
84D0FEC11E274E3700EC3FE5 /* vorbis-tremor-ios.xcodeproj */, 84D0FEC11E274E3700EC3FE5 /* vorbis-tremor-ios.xcodeproj */,
4C902A7015C5735500FBC901 /* Salmon Engine.xcodeproj */, 4C902A7015C5735500FBC901 /* Salmon Engine.xcodeproj */,
4C7B819515C40F770024D61A /* Libs */, 4C7B819515C40F770024D61A /* Libs */,
@ -217,6 +236,8 @@
4CE6A9E315B2F9A4006A3965 /* Game */ = { 4CE6A9E315B2F9A4006A3965 /* Game */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
AC8032272122F8C500DEA5AC /* Bridages */,
AC67C87B211C8DB6003AA164 /* sounds */,
74C3AE251E2E2A40003C07F2 /* creditscode.cpp */, 74C3AE251E2E2A40003C07F2 /* creditscode.cpp */,
74C3AE261E2E2A40003C07F2 /* creditscode.h */, 74C3AE261E2E2A40003C07F2 /* creditscode.h */,
74C3AE271E2E2A40003C07F2 /* game_area_interface.h */, 74C3AE271E2E2A40003C07F2 /* game_area_interface.h */,
@ -228,6 +249,8 @@
74C3AE2D1E2E2A40003C07F2 /* menucode.h */, 74C3AE2D1E2E2A40003C07F2 /* menucode.h */,
84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */, 84D0FECA1E274EBC00EC3FE5 /* main_code.cpp */,
84D0FECB1E274EBC00EC3FE5 /* main_code.h */, 84D0FECB1E274EBC00EC3FE5 /* main_code.h */,
AC8032242122F8B100DEA5AC /* SoundCalls.cpp */,
AC80322B2122FBC100DEA5AC /* SoundCalls.h */,
); );
name = Game; name = Game;
sourceTree = "<group>"; sourceTree = "<group>";
@ -240,6 +263,26 @@
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
AC67C87B211C8DB6003AA164 /* sounds */ = {
isa = PBXGroup;
children = (
AC67C87C211C8DD3003AA164 /* NativeSoundCalls.swift */,
AC67C87E211C8DE3003AA164 /* NativeSoundCallsImpl.swift */,
ACC6F8372121E8DF00CEDC5C /* Sounds.m */,
ACC6F8392121E8ED00CEDC5C /* Sounds.h */,
);
name = sounds;
sourceTree = "<group>";
};
AC8032272122F8C500DEA5AC /* Bridages */ = {
isa = PBXGroup;
children = (
AC8032292122F8DD00DEA5AC /* BridgeDelegate.h */,
AC8032282122F8DC00DEA5AC /* BridgeDelegate.mm */,
);
name = Bridages;
sourceTree = "<group>";
};
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */
@ -326,6 +369,8 @@
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
AC67C882211C8E24003AA164 /* gunshot_sound.mp3 in Resources */,
AC67C883211C8E24003AA164 /* background_sound.mp3 in Resources */,
841270C91E639C2F00776DAE /* Images.xcassets in Resources */, 841270C91E639C2F00776DAE /* Images.xcassets in Resources */,
841D49651E65981600C85722 /* LaunchScreen.storyboard in Resources */, 841D49651E65981600C85722 /* LaunchScreen.storyboard in Resources */,
4C49B2CC15B0991B003512CD /* InfoPlist.strings in Resources */, 4C49B2CC15B0991B003512CD /* InfoPlist.strings in Resources */,
@ -343,15 +388,20 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
74EEBAEF1E2D13A6004C6C65 /* AppDelegate.swift in Sources */, 74EEBAEF1E2D13A6004C6C65 /* AppDelegate.swift in Sources */,
ACC6F8382121E8DF00CEDC5C /* Sounds.m in Sources */,
74C3AE2E1E2E2A40003C07F2 /* creditscode.cpp in Sources */, 74C3AE2E1E2E2A40003C07F2 /* creditscode.cpp in Sources */,
74C3AE2F1E2E2A40003C07F2 /* gamecode.cpp in Sources */, 74C3AE2F1E2E2A40003C07F2 /* gamecode.cpp in Sources */,
AC67C87D211C8DD3003AA164 /* NativeSoundCalls.swift in Sources */,
AC80322A2122F8DD00DEA5AC /* BridgeDelegate.mm in Sources */,
74EEBAF11E2D1C7C004C6C65 /* CustomGLKView.swift in Sources */, 74EEBAF11E2D1C7C004C6C65 /* CustomGLKView.swift in Sources */,
84D0FECC1E274EBC00EC3FE5 /* main_code.cpp in Sources */, 84D0FECC1E274EBC00EC3FE5 /* main_code.cpp in Sources */,
74C3AE301E2E2A40003C07F2 /* loadingcode.cpp in Sources */, 74C3AE301E2E2A40003C07F2 /* loadingcode.cpp in Sources */,
74AC9EBD1E2CE407003C9749 /* ViewController.swift in Sources */, 74AC9EBD1E2CE407003C9749 /* ViewController.swift in Sources */,
74AC9EC11E2CF533003C9749 /* SENamespaceWrapper.cpp in Sources */, 74AC9EC11E2CF533003C9749 /* SENamespaceWrapper.cpp in Sources */,
74C3AE311E2E2A40003C07F2 /* menucode.cpp in Sources */, 74C3AE311E2E2A40003C07F2 /* menucode.cpp in Sources */,
AC67C87F211C8DE3003AA164 /* NativeSoundCallsImpl.swift in Sources */,
4C7AD44C15B1D77700A599F6 /* ios_api.cpp in Sources */, 4C7AD44C15B1D77700A599F6 /* ios_api.cpp in Sources */,
AC8032262122F8B100DEA5AC /* SoundCalls.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@ -0,0 +1,11 @@
import Foundation
protocol NativeSoundCalls {
func playBackgroundSound()
func stopBackgroundSound()
func playGunshotSound()
func stopGunshotSound()
}

View File

@ -0,0 +1,54 @@
import Foundation
import AVFoundation
// example sounds for native calls
// Created by Artem Budarin on 08.08.2018.
public class NativeSoundCallsImpl : NativeSoundCalls {
var backgroundPlayer: AVAudioPlayer?
var gunshotPlayer: AVAudioPlayer?
func playBackgroundSound() {
guard let url = Bundle.main.url(forResource: "background_sound", withExtension: "mp3") else { return }
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
backgroundPlayer = try AVAudioPlayer(contentsOf: url)
//swift 4
//backgroundPlayer = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)
backgroundPlayer?.numberOfLoops = NSInteger.max
backgroundPlayer?.play()
} catch let error {
print(error.localizedDescription)
}
}
func stopBackgroundSound() {
backgroundPlayer?.stop()
}
func playGunshotSound() {
guard let url = Bundle.main.url(forResource: "gunshot_sound", withExtension: "mp3") else { return }
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
gunshotPlayer = try AVAudioPlayer(contentsOf: url)
//swift 4
//gunshotPlayer = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)
gunshotPlayer?.play()
} catch let error {
print(error.localizedDescription)
}
}
func stopGunshotSound() {
gunshotPlayer?.stop()
}
}

22
proj.ios/SoundCalls.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "SoundCalls.h"
#include "BridgeDelegate.h"
void SoundCalls::playBackgroundSound()
{
BridgeDelegate::playBackgroundSound();
}
void SoundCalls::stopBackgroundSound()
{
BridgeDelegate::stopBackgroundSound();
}
void SoundCalls::playGunshotSound()
{
BridgeDelegate::playGunshotSound();
}
void SoundCalls::stopGunshotSound()
{
BridgeDelegate::stopGunshotSound();
}

16
proj.ios/SoundCalls.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef __SOUND_CALLS_H__
#define __SOUND_CALLS_H__
class SoundCalls
{
public:
void playBackgroundSound();
void stopBackgroundSound();
void playGunshotSound();
void stopGunshotSound();
};
#endif // __SOUND_CALLS_H__

16
proj.ios/Sounds.h Normal file
View File

@ -0,0 +1,16 @@
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#define ShareSounds [Sounds shareInstance]
@interface Sounds : NSObject
+ (instancetype)shareInstance;
- (void)playBackgroundSound;
- (void)stopBackgroundSound;
- (void)playGunshotSound;
- (void)stopGunshotSound;
@end

49
proj.ios/Sounds.m Normal file
View File

@ -0,0 +1,49 @@
#import "Sounds.h"
@interface Sounds ()
@property (nonatomic, strong) AVAudioPlayer* backgroundPlayer;
@property (nonatomic, strong) AVAudioPlayer* gunshotPlayer;
@end
@implementation Sounds
static Sounds *_shareInstance;
+(instancetype)shareInstance {
_shareInstance = [[super allocWithZone:NULL] init];
return _shareInstance;
}
- (void)playBackgroundSound {
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"background_sound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
self.backgroundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
self.backgroundPlayer.numberOfLoops = -1; //Infinite
self.backgroundPlayer.play;
}
- (void)stopBackgroundSound {
if (self.backgroundPlayer != nil && self.backgroundPlayer.isPlaying) {
self.backgroundPlayer.stop;
}
}
- (void)playGunshotSound {
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"gunshot_sound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
self.gunshotPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
self.gunshotPlayer.numberOfLoops = 0;
self.gunshotPlayer.play;
}
- (void)stopGunshotSound {
if (self.gunshotPlayer != nil && self.gunshotPlayer.isPlaying) {
self.gunshotPlayer.stop;
}
}
@end

BIN
proj.ios/background_sound.mp3 Executable file

Binary file not shown.

BIN
proj.ios/gunshot_sound.mp3 Executable file

Binary file not shown.