Added support for Android Studio

This commit is contained in:
vladislav.khorev committed 2017-01-10 07:10:36 +03:00
1 parent e4a7822385
commit 99a6b3728d
45 files changed
+1834 -548

No files matched your search

+1
View File
@@ -0,0 +1 @@
/build
+372
View File
@@ -0,0 +1,372 @@
# 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)
# 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.
#ENGINE_PATH = $(SalmonEnginePathCygwin)
#BOOST_PATH = $(LibsPathCygwin)/boost_1_52_0
#OGG_PATH = $(LibsPathCygwin)/libogg-1.3.0
#VORBIS_PATH = $(LibsPathCygwin)/libvorbis-1.3.2
#SQUIRREL_PATH = $(LibsPathCygwin)/sqplus
#LIBPNG_PATH = $(LibsPathCygwin)/libpng_1.4.1_android
#LIBJPEG_PATH = $(LibsPathCygwin)/jpeg-9
#ZIP_PATH = $(LibsPathCygwin)/julienr-libzip-android/jni
set(BOOST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../boost_1_63_0)
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(LIBPNG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libpng_1.4.1_android)
set(LIBJPEG_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/jpeg-9")
set(SQUIRREL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/sqplus)
set(OGG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libogg-1.3.0)
set(VORBIS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libvorbis-1.3.2)
#include_directories(ZIP_PATH)
add_library(zip
${ZIP_PATH}/zip_add.c
${ZIP_PATH}/zip_add_dir.c
${ZIP_PATH}/zip_close.c
${ZIP_PATH}/zip_delete.c
${ZIP_PATH}/zip_dirent.c
${ZIP_PATH}/zip_entry_free.c
${ZIP_PATH}/zip_entry_new.c
${ZIP_PATH}/zip_err_str.c
${ZIP_PATH}/zip_error.c
${ZIP_PATH}/zip_error_clear.c
${ZIP_PATH}/zip_error_get.c
${ZIP_PATH}/zip_error_get_sys_type.c
${ZIP_PATH}/zip_error_strerror.c
${ZIP_PATH}/zip_error_to_str.c
${ZIP_PATH}/zip_fclose.c
${ZIP_PATH}/zip_file_error_clear.c
${ZIP_PATH}/zip_file_error_get.c
${ZIP_PATH}/zip_file_get_offset.c
${ZIP_PATH}/zip_file_strerror.c
${ZIP_PATH}/zip_filerange_crc.c
${ZIP_PATH}/zip_fopen.c
${ZIP_PATH}/zip_fopen_index.c
${ZIP_PATH}/zip_fread.c
${ZIP_PATH}/zip_free.c
${ZIP_PATH}/zip_get_archive_comment.c
${ZIP_PATH}/zip_get_archive_flag.c
${ZIP_PATH}/zip_get_file_comment.c
${ZIP_PATH}/zip_get_num_files.c
${ZIP_PATH}/zip_get_name.c
${ZIP_PATH}/zip_memdup.c
${ZIP_PATH}/zip_name_locate.c
${ZIP_PATH}/zip_new.c
${ZIP_PATH}/zip_open.c
${ZIP_PATH}/zip_rename.c
${ZIP_PATH}/zip_replace.c
${ZIP_PATH}/zip_set_archive_comment.c
${ZIP_PATH}/zip_set_archive_flag.c
${ZIP_PATH}/zip_set_file_comment.c
${ZIP_PATH}/zip_source_buffer.c
${ZIP_PATH}/zip_source_file.c
${ZIP_PATH}/zip_source_filep.c
${ZIP_PATH}/zip_source_free.c
${ZIP_PATH}/zip_source_function.c
${ZIP_PATH}/zip_source_zip.c
${ZIP_PATH}/zip_set_name.c
${ZIP_PATH}/zip_stat.c
${ZIP_PATH}/zip_stat_index.c
${ZIP_PATH}/zip_stat_init.c
${ZIP_PATH}/zip_strerror.c
${ZIP_PATH}/zip_unchange.c
${ZIP_PATH}/zip_unchange_all.c
${ZIP_PATH}/zip_unchange_archive.c
${ZIP_PATH}/zip_unchange_data.c
)
#include_directories(LIBPNG_PATH)
add_library(png
${LIBPNG_PATH}/png.c
${LIBPNG_PATH}/pngerror.c
${LIBPNG_PATH}/pngget.c
${LIBPNG_PATH}/pngmem.c
${LIBPNG_PATH}/pngpread.c
${LIBPNG_PATH}/pngread.c
${LIBPNG_PATH}/pngrio.c
${LIBPNG_PATH}/pngrtran.c
${LIBPNG_PATH}/pngrutil.c
${LIBPNG_PATH}/pngset.c
${LIBPNG_PATH}/pngtrans.c
${LIBPNG_PATH}/pngwio.c
${LIBPNG_PATH}/pngwrite.c
${LIBPNG_PATH}/pngwtran.c
${LIBPNG_PATH}/pngwutil.c
)
include_directories(${LIBJPEG_PATH}/vc10)
add_library(jpeg
${LIBJPEG_PATH}/jaricom.c
${LIBJPEG_PATH}/jcapimin.c
${LIBJPEG_PATH}/jcapistd.c
${LIBJPEG_PATH}/jcarith.c
${LIBJPEG_PATH}/jccoefct.c
${LIBJPEG_PATH}/jccolor.c
${LIBJPEG_PATH}/jcdctmgr.c
${LIBJPEG_PATH}/jchuff.c
${LIBJPEG_PATH}/jcinit.c
${LIBJPEG_PATH}/jcmainct.c
${LIBJPEG_PATH}/jcmarker.c
${LIBJPEG_PATH}/jcmaster.c
${LIBJPEG_PATH}/jcomapi.c
${LIBJPEG_PATH}/jcparam.c
${LIBJPEG_PATH}/jcprepct.c
${LIBJPEG_PATH}/jcsample.c
${LIBJPEG_PATH}/jctrans.c
${LIBJPEG_PATH}/jdapimin.c
${LIBJPEG_PATH}/jdapistd.c
${LIBJPEG_PATH}/jdarith.c
${LIBJPEG_PATH}/jdatadst.c
${LIBJPEG_PATH}/jdatasrc.c
${LIBJPEG_PATH}/jdcoefct.c
${LIBJPEG_PATH}/jdcolor.c
${LIBJPEG_PATH}/jddctmgr.c
${LIBJPEG_PATH}/jdhuff.c
${LIBJPEG_PATH}/jdinput.c
${LIBJPEG_PATH}/jdmainct.c
${LIBJPEG_PATH}/jdmarker.c
${LIBJPEG_PATH}/jdmaster.c
${LIBJPEG_PATH}/jdmerge.c
${LIBJPEG_PATH}/jdpostct.c
${LIBJPEG_PATH}/jdsample.c
${LIBJPEG_PATH}/jdtrans.c
${LIBJPEG_PATH}/jerror.c
${LIBJPEG_PATH}/jfdctflt.c
${LIBJPEG_PATH}/jfdctfst.c
${LIBJPEG_PATH}/jfdctint.c
${LIBJPEG_PATH}/jidctflt.c
${LIBJPEG_PATH}/jidctfst.c
${LIBJPEG_PATH}/jidctint.c
${LIBJPEG_PATH}/jmemmgr.c
${LIBJPEG_PATH}/jmemnobs.c
${LIBJPEG_PATH}/jquant1.c
${LIBJPEG_PATH}/jquant2.c
${LIBJPEG_PATH}/jutils.c
)
#LOCAL_PATH := $(VORBIS_PATH)/lib
#LOCAL_C_INCLUDES := $(VORBIS_PATH)/include
#LOCAL_C_INCLUDES += $(VORBIS_PATH)/include/vorbis
#LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib/src
#LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib/books
#LOCAL_C_INCLUDES += $(VORBIS_PATH)/lib/modes
#LOCAL_C_INCLUDES += $(OGG_PATH)/include
#LOCAL_C_INCLUDES += $(OGG_PATH)/include/ogg
include_directories(${OGG_PATH}/include)
include_directories(${VORBIS_PATH}/include)
add_library(ogg
${OGG_PATH}/src/framing.c
${OGG_PATH}/src/bitwise.c
)
add_library(vorbis
${VORBIS_PATH}/lib/mdct.c
${VORBIS_PATH}/lib/smallft.c
${VORBIS_PATH}/lib/block.c
${VORBIS_PATH}/lib/envelope.c
${VORBIS_PATH}/lib/window.c
${VORBIS_PATH}/lib/lsp.c
${VORBIS_PATH}/lib/lpc.c
${VORBIS_PATH}/lib/analysis.c
${VORBIS_PATH}/lib/synthesis.c
${VORBIS_PATH}/lib/psy.c
${VORBIS_PATH}/lib/info.c
${VORBIS_PATH}/lib/floor1.c
${VORBIS_PATH}/lib/floor0.c
${VORBIS_PATH}/lib/res0.c
${VORBIS_PATH}/lib/mapping0.c
${VORBIS_PATH}/lib/registry.c
${VORBIS_PATH}/lib/codebook.c
${VORBIS_PATH}/lib/sharedbook.c
${VORBIS_PATH}/lib/lookup.c
${VORBIS_PATH}/lib/bitrate.c
${VORBIS_PATH}/lib/vorbisfile.c
)
include_directories(${BOOST_PATH})
add_library(boost
${BOOST_PATH}/libs/thread/src/pthread/thread.cpp
#thread
${BOOST_PATH}/libs/thread/src/pthread/thread.cpp
${BOOST_PATH}/libs/thread/src/pthread/once.cpp
#signals
${BOOST_PATH}/libs/signals/src/connection.cpp
${BOOST_PATH}/libs/signals/src/named_slot_map.cpp
${BOOST_PATH}/libs/signals/src/signal_base.cpp
${BOOST_PATH}/libs/signals/src/slot.cpp
${BOOST_PATH}/libs/signals/src/trackable.cpp
#system
${BOOST_PATH}/libs/system/src/error_code.cpp
#regex
${BOOST_PATH}/libs/regex/src/c_regex_traits.cpp
${BOOST_PATH}/libs/regex/src/cpp_regex_traits.cpp
${BOOST_PATH}/libs/regex/src/cregex.cpp
${BOOST_PATH}/libs/regex/src/fileiter.cpp
${BOOST_PATH}/libs/regex/src/icu.cpp
${BOOST_PATH}/libs/regex/src/instances.cpp
${BOOST_PATH}/libs/regex/src/posix_api.cpp
${BOOST_PATH}/libs/regex/src/regex.cpp
${BOOST_PATH}/libs/regex/src/regex_debug.cpp
${BOOST_PATH}/libs/regex/src/regex_raw_buffer.cpp
${BOOST_PATH}/libs/regex/src/regex_traits_defaults.cpp
${BOOST_PATH}/libs/regex/src/static_mutex.cpp
${BOOST_PATH}/libs/regex/src/usinstances.cpp
${BOOST_PATH}/libs/regex/src/w32_regex_traits.cpp
${BOOST_PATH}/libs/regex/src/wc_regex_traits.cpp
${BOOST_PATH}/libs/regex/src/wide_posix_api.cpp
${BOOST_PATH}/libs/regex/src/winstances.cpp
#date_time
${BOOST_PATH}/libs/date_time/src/gregorian/greg_month.cpp
${BOOST_PATH}/libs/date_time/src/gregorian/greg_weekday.cpp
${BOOST_PATH}/libs/date_time/src/gregorian/date_generators.cpp
)
find_library( # Sets the name of the path variable.
z-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
z )
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 )
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
include_directories(${BOOST_PATH})
include_directories(${LIBPNG_PATH})
include_directories(${LIBJPEG_PATH})
include_directories(${ZIP_PATH})
include_directories(${BOOST_GIL_PATH})
add_definitions(-DTARGET_ANDROID)
add_library( # Sets the name of the library.
engine
# 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.
#testcpp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/DataTypes/DataTypes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/DataTypes/NewDataTypes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/FileUtils/FileUtils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/JniApi/JniApi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/JniApi/JniApplication.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/Console/Console.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/SerializeInterface/SerializeInterface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/Network/Network.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/PngHelper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/JpegHelper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/TgaLoader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/SimpleTimer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Utils/ThreadUtils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/TextureManager/SalmonTexture.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/ShaderManager/ShaderManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/FrameManager/FrameManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/LightManager/LightManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/SoundManager/SoundManagerAndroid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/SoundManager/SoundManagerDataTypes.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/FontManager/FontManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/ScriptManager/ScriptManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/SmartValueManager/SmartValueManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/GUIManager/GUIManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/GUIManager/ButtonWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/GUIManager/WidgetXmlParsers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/HalibutAnimation/HalibutAnimation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/ModelManager/ModelManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/ModelManager/NewModelManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/SimpleLand/SimpleLand.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/PhysicsManager/PhysicsManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Render/RenderMisc.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Render/RenderParams.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Render/SalmonRender/BackgroundCubemap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Render/SalmonRender/SalmonRenderInterface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Render/SalmonRender/SalmonRenderGLES20.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Render/SalmonRender/SalmonRenderAndroid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Render/SalmonRender/Cameras.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/Animation/SalmonAnimation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/SalmonEngineAndroid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../src/SalmonEngineInterface.cpp
)
target_link_libraries(engine
${z-lib}
${log-lib}
${GLESv2-lib}
png
zip
boost
jpeg
ogg
vorbis
)
+38
View File
@@ -0,0 +1,38 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions -Wno-c++11-narrowing"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}
+17
View File
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
@@ -0,0 +1,26 @@
package fishrungames.salmonengineandroid;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("fishrungames.salmonengineandroid", appContext.getPackageName());
}
}
+17
View File
@@ -0,0 +1,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fishrungames.salmonengineandroid">
<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:screenOrientation="landscape"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden"
android:noHistory="true">
</application>
<uses-feature android:glEsVersion="0x00020000"/>
</manifest>
+3
View File
@@ -0,0 +1,3 @@
#include <jni.h>
#include <string>
@@ -0,0 +1,448 @@
package fishrungames.salmonengineandroid;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.opengl.GLSurfaceView;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;
//import android.net.Uri;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
public class EngineWrapper {
static class CustomGestureListener extends SimpleOnGestureListener
{
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY)
{
EngineWrapper.OnFling(velocityX, velocityY, e2.getEventTime());
return true;
}
}
static class JniDestroyRunnable implements Runnable
{
public void run()
{
EngineWrapper.Destroy();
}
}
static ContextWrapper Instance = null;
static Map<String, Integer> FileMap = new HashMap<String, Integer>();
static Map<String, Integer> SoundMap = new HashMap<String, Integer>();
static Context context;
static SoundPool soundPool;
static MediaPlayer mp;
static GLSurfaceView mView;
static GestureDetector customGestureDetector = new GestureDetector(new CustomGestureListener());
public static void SetActivityInstance(ContextWrapper inst)
{
Instance = inst;
context = Instance.getBaseContext();
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
mp = new MediaPlayer();
}
public static void SetView(GLSurfaceView view)
{
mView = view;
}
public static String GetApplicationDir()
{
return Instance.getFilesDir().getPath();
}
public static void AddToFileMap(String s, Integer i)
{
FileMap.put(s, i);
}
public synchronized static int OpenFile(String fileName)
{
String newFileName;
int i = fileName.lastIndexOf(".");
if (i == -1)
{
newFileName = fileName;
}
else
{
newFileName = fileName.substring(0, i);
}
if (!FileMap.containsKey(newFileName))
{
return 0;
}
Integer id = FileMap.get(newFileName);
try
{
InputStream is = Instance.getResources().openRawResource(id);
byte[] buffer = new byte[256];
int bytesRead;
CreateFile(is.available());
while ((bytesRead = is.read(buffer, 0, 256)) != -1)
{
WriteToFile(buffer, bytesRead);
}
} catch (Throwable t) {
ConsoleOut("Exception in FileWrapper::OpenFile!\n");
return 0;
}
return 1;
}
public static native void SetupEnviroment();
public static native void SetupApkFilePath(String s);
public static native void ConsoleOut(String s);
public static native void CreateFile(int fileSize);
public static native void WriteToFile(byte [] buffer, int bufferSize);
public static void LoadSound(String soundFileName)
{
if (SoundMap.containsKey(soundFileName))
{
return;
}
/*
String newFileName;
int i = soundFileName.lastIndexOf(".");
if (i == -1)
{
newFileName = soundFileName;
}
else
{
newFileName = soundFileName.substring(0, i);
}*/
//int soundId = soundPool.load(context, FileMap.get(newFileName), 1);
AssetFileDescriptor afd = null;
try
{
afd = Instance.getAssets().openFd(soundFileName);
} catch (IOException e)
{
e.printStackTrace();
}
int soundId = soundPool.load(afd, 1);
SoundMap.put(soundFileName, soundId);
}
public static void ReleaseAllSoundsAndMusic()
{
mp.stop();
mp.reset();
//soundPool.autoPause();
Enumeration<Integer> i = Collections.enumeration(SoundMap.values());
while(i.hasMoreElements())
{
soundPool.stop(i.nextElement());
}
SoundMap.clear();
}
public static void PauseAllSoundsAndMusic()
{
//NIU right now
soundPool.autoPause();
mp.pause();
}
public static void ResumeAllSoundsAndMusic()
{
//NIU right now
soundPool.autoResume();
mp.start();
}
public static void StopMusic()
{
mp.stop();
mp.reset();
}
public static void PlayMusic(String musicFileName)
{
InnerPlayMusic(musicFileName, false);
}
public static void PlayMusicLooped(String musicFileName)
{
InnerPlayMusic(musicFileName, true);
}
private static void InnerPlayMusic(String musicFileName, boolean looped)
{
/*
String newFileName;
int i = musicFileName.lastIndexOf(".");
if (i == -1)
{
newFileName = musicFileName;
}
else
{
newFileName = musicFileName.substring(0, i);
}
*/
try
{
//Uri path = Uri.parse("android.resource://"+Instance.getPackageName()+"/assets/"+newFileName);
AssetFileDescriptor afd = null;
try
{
afd = Instance.getAssets().openFd(musicFileName);
} catch (IOException e)
{
e.printStackTrace();
}
//mp.setDataSource(context, path);
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
mp.prepare();
mp.setLooping(looped);
mp.start();
} catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void PlaySound(String soundFileName)
{
if (!SoundMap.containsKey(soundFileName))
{
return;
}
int soundId = SoundMap.get(soundFileName);
soundPool.play(soundId, 1,1,1,0,1);
}
public static void LoadSalmonEngineLibrary()
{
System.loadLibrary("engine");
}
static
{
//System.loadLibrary("gnustl_shared");
}
//Application methods
public static native void Update(long dt);
public static native void Destroy();
public static native int IsInited();
public static native void OnTapDown(float x, float y, long time);
public static native void OnTapUp(float x, float y, long time);
public static native void OnTapUpAfterMove(float x, float y, long time);
public static native void OnTapMove(float x, float y, long time);
public static native void OnFling(float velocityX, float velocityY, long time);
public static native void OnScroll(float distanceX, float distanceY, long time);
public static native void OnKeyPress(int keyCode);
public static void CallDestroy()
{
mView.queueEvent(new JniDestroyRunnable());
}
public static void ProcessKeyDown(int keyCode, KeyEvent event)
{
int ascii_keycode = keyCode;
if (keyCode == KeyEvent.KEYCODE_DEL)
{
ascii_keycode = 8; //Hack - getUnicodeChar does not recognize backspace
}
else
{
ascii_keycode = event.getUnicodeChar();
}
OnKeyPress(ascii_keycode);
}
static boolean IsScrolling = false;
static float PrevMovePosX = 0;
static float PrevMovePosY = 0;
static boolean EnableFlingGesture = false;
public static void ProcessTouchEvent(MotionEvent event)
{
if (EnableFlingGesture)
{
if (customGestureDetector.onTouchEvent(event))
{
return;
}
}
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
float x = event.getX();
float y = (float) mView.getHeight() - event.getY();
float oldX = PrevMovePosX;
float oldY = (float) mView.getHeight() - PrevMovePosY;
float shiftX = x - oldX;
float shiftY = y - oldY;
if (Math.abs(shiftX) > 0.001f || Math.abs(shiftY) > 0.001f)
{
OnScroll(-shiftX, -shiftY, event.getEventTime());
}
PrevMovePosX = event.getX();
PrevMovePosY = event.getY();
IsScrolling = true;
}
if (event.getAction() == MotionEvent.ACTION_UP)
{
float x = event.getX();
float y = (float) mView.getHeight() - event.getY();
if (IsScrolling)
{
IsScrolling = false;
OnTapUpAfterMove(x, y, event.getEventTime());
}
else
{
OnTapUp(x, y, event.getEventTime());
}
}
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
float x = event.getX();
float y = (float) mView.getHeight() - event.getY();
PrevMovePosX = event.getX();
PrevMovePosY = event.getY();
OnTapDown(x, y, event.getEventTime());
}
}
}
@@ -0,0 +1,289 @@
package fishrungames.salmonengineandroid;
import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.Log;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
/*
This is a OpenGL View template. Do not change this code - derive your own class instead!!
*/
public class GLViewAncestor extends GLSurfaceView
{
private static String TAG = "GL2JNIView";
private static final boolean DEBUG = false;
public GLViewAncestor(Context context)
{
super(context);
}
public void init(boolean translucent, int depth, int stencil)
{
/*
* By default, GLSurfaceView() creates a RGB_565 opaque surface. If we
* want a translucent one, we should change the surface's format here,
* using PixelFormat.TRANSLUCENT for GL Surfaces is interpreted as any
* 32-bit surface with alpha by SurfaceFlinger.
*/
if (translucent)
{
this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
/*
* Setup the context factory for 2.0 rendering. See ContextFactory class
* definition below
*/
setEGLContextFactory(new ContextFactory());
/*
* We need to choose an EGLConfig that matches the format of our surface
* exactly. This is going to be done in our custom config chooser. See
* ConfigChooser class definition below.
*/
setEGLConfigChooser(translucent ? new ConfigChooser(8, 8, 8, 8, depth,
stencil) : new ConfigChooser(5, 6, 5, 0, depth, stencil));
}
private static class ContextFactory implements
GLSurfaceView.EGLContextFactory
{
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
@Override
public EGLContext createContext(EGL10 egl, EGLDisplay display,
EGLConfig eglConfig)
{
Log.w(TAG, "creating OpenGL ES 2.0 context");
checkEglError("Before eglCreateContext", egl);
int[] attrib_list =
{ EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
EGLContext context = egl.eglCreateContext(display, eglConfig,
EGL10.EGL_NO_CONTEXT, attrib_list);
checkEglError("After eglCreateContext", egl);
return context;
}
@Override
public void destroyContext(EGL10 egl, EGLDisplay display,
EGLContext context)
{
egl.eglDestroyContext(display, context);
}
}
private static void checkEglError(String prompt, EGL10 egl)
{
int error;
while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS)
{
Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));
}
}
private static class ConfigChooser implements
GLSurfaceView.EGLConfigChooser
{
public ConfigChooser(int r, int g, int b, int a, int depth, int stencil)
{
mRedSize = r;
mGreenSize = g;
mBlueSize = b;
mAlphaSize = a;
mDepthSize = depth;
mStencilSize = stencil;
}
/*
* This EGL config specification is used to specify 2.0 rendering. We
* use a minimum size of 4 bits for red/green/blue, but will perform
* actual matching in chooseConfig() below.
*/
private static int EGL_OPENGL_ES2_BIT = 4;
private static int[] s_configAttribs2 =
{ EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4,
EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE };
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
/*
* Get the number of minimally matching EGL configurations
*/
int[] num_config = new int[1];
egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
int numConfigs = num_config[0];
if (numConfigs <= 0)
{
throw new IllegalArgumentException(
"No configs match configSpec");
}
/*
* Allocate then read the array of minimally matching EGL configs
*/
EGLConfig[] configs = new EGLConfig[numConfigs];
egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs,
num_config);
if (DEBUG)
{
printConfigs(egl, display, configs);
}
/*
* Now return the "best" one
*/
return chooseConfig(egl, display, configs);
}
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs)
{
for (EGLConfig config : configs)
{
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
// We need at least mDepthSize and mStencilSize bits
if (d < mDepthSize || s < mStencilSize)
continue;
// We want an *exact* match for red/green/blue/alpha
int r = findConfigAttrib(egl, display, config,
EGL10.EGL_RED_SIZE, 0);
int g = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
int b = findConfigAttrib(egl, display, config,
EGL10.EGL_BLUE_SIZE, 0);
int a = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
if (r == mRedSize && g == mGreenSize && b == mBlueSize
&& a == mAlphaSize)
return config;
}
return null;
}
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
EGLConfig config, int attribute, int defaultValue)
{
if (egl.eglGetConfigAttrib(display, config, attribute, mValue))
{
return mValue[0];
}
return defaultValue;
}
private void printConfigs(EGL10 egl, EGLDisplay display,
EGLConfig[] configs)
{
int numConfigs = configs.length;
Log.w(TAG, String.format("%d configurations", numConfigs));
for (int i = 0; i < numConfigs; i++)
{
Log.w(TAG, String.format("Configuration %d:\n", i));
printConfig(egl, display, configs[i]);
}
}
private void printConfig(EGL10 egl, EGLDisplay display, EGLConfig config)
{
int[] attributes =
{
EGL10.EGL_BUFFER_SIZE,
EGL10.EGL_ALPHA_SIZE,
EGL10.EGL_BLUE_SIZE,
EGL10.EGL_GREEN_SIZE,
EGL10.EGL_RED_SIZE,
EGL10.EGL_DEPTH_SIZE,
EGL10.EGL_STENCIL_SIZE,
EGL10.EGL_CONFIG_CAVEAT,
EGL10.EGL_CONFIG_ID,
EGL10.EGL_LEVEL,
EGL10.EGL_MAX_PBUFFER_HEIGHT,
EGL10.EGL_MAX_PBUFFER_PIXELS,
EGL10.EGL_MAX_PBUFFER_WIDTH,
EGL10.EGL_NATIVE_RENDERABLE,
EGL10.EGL_NATIVE_VISUAL_ID,
EGL10.EGL_NATIVE_VISUAL_TYPE,
0x3030, // EGL10.EGL_PRESERVED_RESOURCES,
EGL10.EGL_SAMPLES,
EGL10.EGL_SAMPLE_BUFFERS,
EGL10.EGL_SURFACE_TYPE,
EGL10.EGL_TRANSPARENT_TYPE,
EGL10.EGL_TRANSPARENT_RED_VALUE,
EGL10.EGL_TRANSPARENT_GREEN_VALUE,
EGL10.EGL_TRANSPARENT_BLUE_VALUE,
0x3039, // EGL10.EGL_BIND_TO_TEXTURE_RGB,
0x303A, // EGL10.EGL_BIND_TO_TEXTURE_RGBA,
0x303B, // EGL10.EGL_MIN_SWAP_INTERVAL,
0x303C, // EGL10.EGL_MAX_SWAP_INTERVAL,
EGL10.EGL_LUMINANCE_SIZE, EGL10.EGL_ALPHA_MASK_SIZE,
EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RENDERABLE_TYPE,
0x3042 // EGL10.EGL_CONFORMANT
};
String[] names =
{ "EGL_BUFFER_SIZE", "EGL_ALPHA_SIZE", "EGL_BLUE_SIZE",
"EGL_GREEN_SIZE", "EGL_RED_SIZE", "EGL_DEPTH_SIZE",
"EGL_STENCIL_SIZE", "EGL_CONFIG_CAVEAT",
"EGL_CONFIG_ID", "EGL_LEVEL", "EGL_MAX_PBUFFER_HEIGHT",
"EGL_MAX_PBUFFER_PIXELS", "EGL_MAX_PBUFFER_WIDTH",
"EGL_NATIVE_RENDERABLE", "EGL_NATIVE_VISUAL_ID",
"EGL_NATIVE_VISUAL_TYPE", "EGL_PRESERVED_RESOURCES",
"EGL_SAMPLES", "EGL_SAMPLE_BUFFERS",
"EGL_SURFACE_TYPE", "EGL_TRANSPARENT_TYPE",
"EGL_TRANSPARENT_RED_VALUE",
"EGL_TRANSPARENT_GREEN_VALUE",
"EGL_TRANSPARENT_BLUE_VALUE",
"EGL_BIND_TO_TEXTURE_RGB", "EGL_BIND_TO_TEXTURE_RGBA",
"EGL_MIN_SWAP_INTERVAL", "EGL_MAX_SWAP_INTERVAL",
"EGL_LUMINANCE_SIZE", "EGL_ALPHA_MASK_SIZE",
"EGL_COLOR_BUFFER_TYPE", "EGL_RENDERABLE_TYPE",
"EGL_CONFORMANT" };
int[] value = new int[1];
for (int i = 0; i < attributes.length; i++)
{
int attribute = attributes[i];
String name = names[i];
if (egl.eglGetConfigAttrib(display, config, attribute, value))
{
Log.w(TAG, String.format(" %s: %d\n", name, value[0]));
} else
{
// Log.w(TAG, String.format(" %s: failed\n", name));
while (egl.eglGetError() != EGL10.EGL_SUCCESS)
;
}
}
}
// Subclasses can adjust these values:
protected int mRedSize;
protected int mGreenSize;
protected int mBlueSize;
protected int mAlphaSize;
protected int mDepthSize;
protected int mStencilSize;
private int[] mValue = new int[1];
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
+3
View File
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">SalmonEngineAndroid</string>
</resources>
+11
View File
@@ -0,0 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>
@@ -0,0 +1,17 @@
package fishrungames.salmonengineandroid;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}