refactor android with new renderer (#1133)

This commit is contained in:
minggo
2018-02-28 14:55:33 +08:00
committed by GitHub
parent a3dc57d9b7
commit cd0e15cd7f
40 changed files with 666 additions and 3054 deletions
+42 -30
View File
@@ -2,10 +2,8 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# cis is short name for cocos2dx_internal_static
# Shorter name could avoid compilation errors on Windows system which has a limitation of 260 bytes for build path.
LOCAL_MODULE := cis
LOCAL_MODULE_FILENAME := libcocos2dxinternal
LOCAL_MODULE := cocos2dx_static
LOCAL_MODULE_FILENAME := libcocos2d
LOCAL_ARM_MODE := arm
@@ -79,6 +77,35 @@ renderer/renderer//Scene.cpp \
renderer/renderer/Technique.cpp \
renderer/renderer/View.cpp \
renderer/renderer/ForwardRenderer.cpp \
scripting/js-bindings/auto/jsb_gfx_auto.cpp \
scripting/js-bindings/manual/jsb_classtype.cpp \
scripting/js-bindings/manual/jsb_conversions.cpp \
scripting/js-bindings/manual/jsb_gfx_manual.cpp \
scripting/js-bindings/manual/jsb_global.cpp \
scripting/js-bindings/manual/jsb_renderer_manual.cpp \
scripting/js-bindings/auto/jsb_renderer_auto.cpp \
scripting/js-bindings/jswrapper/config.cpp \
scripting/js-bindings/jswrapper/HandleObject.cpp \
scripting/js-bindings/jswrapper/MappingUtils.cpp \
scripting/js-bindings/jswrapper/RefCounter.cpp \
scripting/js-bindings/jswrapper/Value.cpp \
scripting/js-bindings/jswrapper/State.cpp \
scripting/js-bindings/jswrapper/v8/Class.cpp \
scripting/js-bindings/jswrapper/v8/Object.cpp \
scripting/js-bindings/jswrapper/v8/ObjectWrap.cpp \
scripting/js-bindings/jswrapper/v8/SHA1.cpp \
scripting/js-bindings/jswrapper/v8/ScriptEngine.cpp \
scripting/js-bindings/jswrapper/v8/Utils.cpp \
scripting/js-bindings/jswrapper/v8/env.cc \
scripting/js-bindings/jswrapper/v8/inspector_agent.cc \
scripting/js-bindings/jswrapper/v8/inspector_io.cc \
scripting/js-bindings/jswrapper/v8/inspector_socket.cc \
scripting/js-bindings/jswrapper/v8/inspector_socket_server.cc \
scripting/js-bindings/jswrapper/v8/node.cc \
scripting/js-bindings/jswrapper/v8/node_debug_options.cc \
scripting/js-bindings/jswrapper/v8/util.cc \
scripting/js-bindings/jswrapper/v8/http_parser.c \
scripting/js-bindings/event/EventDispatcher.cpp \
../external/sources/firefox/WebGLFormats.cpp \
../external/sources/firefox/WebGLTexelConversions.cpp \
../external/sources/firefox/mozilla/Assertions.cpp \
@@ -149,12 +176,17 @@ renderer/renderer/ForwardRenderer.cpp \
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/.. \
$(LOCAL_PATH)/platform \
$(LOCAL_PATH)/editor-support \
$(LOCAL_PATH)/../external/android/$(TARGET_ARCH_ABI)/include \
$(LOCAL_PATH)/../external/sources \
$(LOCAL_PATH)/../external/sources/firefox \
$(LOCAL_PATH)/renderer
$(LOCAL_PATH)/renderer \
$(LOCAL_PATH)/scripting/js-bindings/manual \
$(LOCAL_PATH)/scripting/js-bindings/manual/platform/android \
$(LOCAL_PATH)/scripting/js-bindings/auto \
$(LOCAL_PATH)/renderer/gfx
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/.. \
@@ -169,20 +201,21 @@ LOCAL_EXPORT_LDLIBS := -lGLESv2 \
-landroid
LOCAL_STATIC_LIBRARIES := cocos_freetype2_static
# LOCAL_STATIC_LIBRARIES += spine_static
# LOCAL_STATIC_LIBRARIES += creator_static
LOCAL_STATIC_LIBRARIES += cocos_png_static
LOCAL_STATIC_LIBRARIES += cocos_jpeg_static
LOCAL_STATIC_LIBRARIES += cocos_tiff_static
LOCAL_STATIC_LIBRARIES += cocos_webp_static
# LOCAL_STATIC_LIBRARIES += cocos_chipmunk_static
LOCAL_STATIC_LIBRARIES += cocos_zlib_static
LOCAL_STATIC_LIBRARIES += uv_static
LOCAL_STATIC_LIBRARIES += v8_static
# LOCAL_STATIC_LIBRARIES += audioengine_static
# LOCAL_STATIC_LIBRARIES += cocos_network_static
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dxandroid_static
LOCAL_WHOLE_STATIC_LIBRARIES += cpufeatures
# define the macro to compile through support/zip_support/ioapi.c
LOCAL_CFLAGS := -DUSE_FILE32API -fexceptions
LOCAL_CFLAGS := -DUSE_FILE32API -fexceptions -DHAVE_INSPECTOR
# Issues #9968
#ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
@@ -195,33 +228,12 @@ LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations
include $(BUILD_STATIC_LIBRARY)
#==============================================================
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dx_static
LOCAL_MODULE_FILENAME := libcocos2d
# LOCAL_STATIC_LIBRARIES := audioengine_static
# LOCAL_STATIC_LIBRARIES += cocos_network_static
# LOCAL_STATIC_LIBRARIES += cocos_ui_static
# LOCAL_STATIC_LIBRARIES += spine_static
# LOCAL_STATIC_LIBRARIES += dragonbones_static
# LOCAL_STATIC_LIBRARIES += creator_static
LOCAL_STATIC_LIBRARIES := cis
include $(BUILD_STATIC_LIBRARY)
#==============================================================
#$(call import-module,.)
$(call import-module,android)
# $(call import-module,editor-support/cocostudio)
# $(call import-module,editor-support/cocosbuilder)
# $(call import-module,editor-support/dragonbones/proj.android)
# $(call import-module,editor-support/spine)
# $(call import-module,editor-support/creator)
$(call import-module,platform/android)
# $(call import-module,audio/android)
# $(call import-module,network)
# $(call import-module,ui)
$(call import-module,extensions)
$(call import-module,android/cpufeatures)
+1 -1
View File
@@ -47,7 +47,7 @@ public:
WINDOWS, /**< Windows */
LINUX, /**< Linux */
MAC, /**< Mac OS X*/
ANDROID, /**< Android */
ANDROIDOS, /**< Android, because ANDROID is a macro, so use ANDROIDOS instead */
IPHONE, /**< iPhone */
IPAD, /**< iPad */
};
+4 -6
View File
@@ -9,13 +9,9 @@ LOCAL_MODULE_FILENAME := libcocos2dandroid
LOCAL_SRC_FILES := \
CCDevice-android.cpp \
CCFileUtils-android.cpp \
javaactivity-android.cpp \
jni/Java_org_cocos2dx_lib_Cocos2dxAccelerometer.cpp \
jni/Java_org_cocos2dx_lib_Cocos2dxBitmap.cpp \
jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp \
jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp \
CCApplication-android.cpp \
jni/JniImp.cpp \
jni/JniHelper.cpp \
jni/TouchesJni.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
@@ -29,4 +25,6 @@ LOCAL_EXPORT_LDLIBS := -lGLESv1_CM \
-llog \
-landroid
LOCAL_STATIC_LIBRARIES := v8_static
include $(BUILD_STATIC_LIBRARY)
@@ -0,0 +1,194 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "platform/CCApplication.h"
#include <android/log.h>
#include <jni.h>
#include <cstring>
#include "platform/android/jni/JniImp.h"
#define LOG_TAG "CCApplication_android Debug"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
// FIXME: using ndk-r10c will cause the next function could not be found. It may be a bug of ndk-r10c.
// Here is the workaround method to fix the problem.
#ifdef __aarch64__
extern "C" size_t __ctype_get_mb_cur_max(void)
{
return (size_t) sizeof(wchar_t);
}
#endif
NS_CC_BEGIN
Application::Application(const std::string& name)
{
}
Application::~Application()
{
}
void Application::start()
{
if(!applicationDidFinishLaunching())
return;
}
void Application::setMultitouch(bool /*value*/)
{
}
bool Application::applicationDidFinishLaunching()
{
return true;
}
void Application::applicationDidEnterBackground()
{
}
void Application::applicationWillEnterForeground()
{
}
void Application::setAnimationInterval(float interval)
{
_animationInterval = interval;
setAnimationIntervalJNI(_animationInterval);
}
std::string Application::getCurrentLanguageCode() const
{
std::string language = getCurrentLanguageJNI();
return language.substr(0, 2);
}
Application::LanguageType Application::getCurrentLanguage() const
{
std::string languageName = getCurrentLanguageJNI();
const char* pLanguageName = languageName.c_str();
LanguageType ret = LanguageType::ENGLISH;
if (0 == strcmp("zh", pLanguageName))
{
ret = LanguageType::CHINESE;
}
else if (0 == strcmp("en", pLanguageName))
{
ret = LanguageType::ENGLISH;
}
else if (0 == strcmp("fr", pLanguageName))
{
ret = LanguageType::FRENCH;
}
else if (0 == strcmp("it", pLanguageName))
{
ret = LanguageType::ITALIAN;
}
else if (0 == strcmp("de", pLanguageName))
{
ret = LanguageType::GERMAN;
}
else if (0 == strcmp("es", pLanguageName))
{
ret = LanguageType::SPANISH;
}
else if (0 == strcmp("ru", pLanguageName))
{
ret = LanguageType::RUSSIAN;
}
else if (0 == strcmp("nl", pLanguageName))
{
ret = LanguageType::DUTCH;
}
else if (0 == strcmp("ko", pLanguageName))
{
ret = LanguageType::KOREAN;
}
else if (0 == strcmp("ja", pLanguageName))
{
ret = LanguageType::JAPANESE;
}
else if (0 == strcmp("hu", pLanguageName))
{
ret = LanguageType::HUNGARIAN;
}
else if (0 == strcmp("pt", pLanguageName))
{
ret = LanguageType::PORTUGUESE;
}
else if (0 == strcmp("ar", pLanguageName))
{
ret = LanguageType::ARABIC;
}
else if (0 == strcmp("nb", pLanguageName))
{
ret = LanguageType::NORWEGIAN;
}
else if (0 == strcmp("pl", pLanguageName))
{
ret = LanguageType::POLISH;
}
else if (0 == strcmp("tr", pLanguageName))
{
ret = LanguageType::TURKISH;
}
else if (0 == strcmp("uk", pLanguageName))
{
ret = LanguageType::UKRAINIAN;
}
else if (0 == strcmp("ro", pLanguageName))
{
ret = LanguageType::ROMANIAN;
}
else if (0 == strcmp("bg", pLanguageName))
{
ret = LanguageType::BULGARIAN;
}
return ret;
}
Application::Platform Application::getPlatform() const
{
return Platform::ANDROIDOS;
}
void Application::onCreateView(int& /*x*/, int& /*y*/, int& /*width*/, int& /*height*/,
PixelFormat& /*pixelformat*/, DepthFormat& /*depthFormat*/, int& /*multisamplingCount*/)
{
}
bool Application::openURL(const std::string &url)
{
return openURLJNI(url);
}
NS_CC_END
@@ -29,7 +29,7 @@ THE SOFTWARE.
#include "platform/android/CCFileUtils-android.h"
#include "platform/android/jni/JniHelper.h"
#include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
#include "platform/android/jni/JniImp.h"
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#include "base/ZipUtils.h"
@@ -90,7 +90,7 @@ bool FileUtilsAndroid::init()
{
_defaultResRootPath = ASSETS_FOLDER_NAME;
std::string assetsPath(getApkPath());
std::string assetsPath(getApkPathJNI());
if (assetsPath.find("/obb/") != std::string::npos)
{
obbfile = new ZipFile(assetsPath);
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libControllerManualAdapter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.lib"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"/>
</manifest>
@@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="androidControllerManualAdapter" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
@@ -1,23 +0,0 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# 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 *;
#}
-libraryjars com.bda.controller.jar
-dontwarn com.bda.controller.*
-keep class org.cocos2dx.lib.*{*;}
@@ -1,309 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.lang.reflect.Method;
import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener;
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat;
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener;
import org.cocos2dx.lib.Cocos2dxActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.util.Log;
public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener {
// ===========================================================
// Constants
// ===========================================================
private final static String TAG = GameControllerActivity.class.getSimpleName();
public static final int DRIVERTYPE_NIBIRU = 0;
public static final int DRIVERTYPE_MOGA = 1;
public static final int DRIVERTYPE_OUYA = 2;
public static final int DRIVERTYPE_STANDARD = 3;
public static final int DRIVERTYPE_UNKNOWN = 4;
// ===========================================================
// Fields
// ===========================================================
private static GameControllerActivity sGameControllerActivity;
private InputManagerCompat mInputManager = null;
protected GameControllerHelper mControllerHelper = null;
protected GameControllerDelegate mControllerNibiru = null;
protected GameControllerDelegate mControllerMoga = null;
protected GameControllerDelegate mControllerOuya = null;
public void connectController(int driveType){
try {
ClassLoader loader = sGameControllerActivity.getClassLoader();
Class<?> controllerDelegate = null;
if (driveType == DRIVERTYPE_MOGA) {
if (mControllerMoga != null) {
return;
}
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga");
} else if (driveType == DRIVERTYPE_NIBIRU) {
if (mControllerNibiru != null) {
mControllerNibiru.onCreate(sGameControllerActivity);
mControllerNibiru.onResume();
return;
}
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
} else if (driveType == DRIVERTYPE_OUYA) {
if (mControllerOuya != null) {
return;
}
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya");
}
GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance();
sGameControllerActivity.setGameControllerInstance(instance, driveType);
if (driveType == DRIVERTYPE_NIBIRU) {
Method method = controllerDelegate.getDeclaredMethod("onResume");
method.invoke(instance);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) {
if (driveType == DRIVERTYPE_NIBIRU) {
mControllerNibiru = controllerDelegate;
}else if (driveType == DRIVERTYPE_MOGA) {
mControllerMoga = controllerDelegate;
}
else if (driveType == DRIVERTYPE_OUYA) {
mControllerOuya = controllerDelegate;
}
controllerDelegate.setControllerEventListener(mControllerEventListener);
controllerDelegate.onCreate(sGameControllerActivity);
}
public GameControllerDelegate getGameControllerDelegate(int driveType){
if (driveType == DRIVERTYPE_NIBIRU) {
return mControllerNibiru;
}else if (driveType == DRIVERTYPE_MOGA) {
return mControllerMoga;
}
else if (driveType == DRIVERTYPE_OUYA) {
return mControllerOuya;
}
return null;
}
ControllerEventListener mControllerEventListener = new ControllerEventListener() {
@Override
public void onButtonEvent(String vendorName, int controller, int button,
boolean isPressed, float value, boolean isAnalog) {
GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
}
@Override
public void onAxisEvent(String vendorName, int controller, int axisID,
float value, boolean isAnalog) {
GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog);
}
@Override
public void onConnected(String vendorName, int controller) {
GameControllerAdapter.onConnected(vendorName, controller);
}
@Override
public void onDisconnected(String vendorName, int controller) {
GameControllerAdapter.onDisconnected(vendorName, controller);
}
};
// ===========================================================
// Constructors
// ===========================================================
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sGameControllerActivity = this;
mInputManager = InputManagerCompat.Factory.getInputManager(this);
mInputManager.registerInputDeviceListener(this, null);
if (mControllerNibiru != null) {
mControllerNibiru.onCreate(this);
}
if (mControllerMoga != null) {
mControllerMoga.onCreate(this);
}
if (mControllerOuya != null) {
mControllerOuya.onCreate(this);
}
if (mControllerHelper == null) {
mControllerHelper = new GameControllerHelper(this);
}
}
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
if (mControllerNibiru != null) {
handled |= mControllerNibiru.dispatchKeyEvent(event);
}
if (handled == false && mControllerMoga != null) {
handled |= mControllerMoga.dispatchKeyEvent(event);
}
if (handled == false && mControllerOuya != null) {
handled |= mControllerOuya.dispatchKeyEvent(event);
}
if (handled == false) {
handled |= mControllerHelper.dispatchKeyEvent(event);
}
return handled || super.dispatchKeyEvent(event);
}
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
boolean handled = false;
if (mControllerNibiru != null) {
handled |= mControllerNibiru.dispatchGenericMotionEvent(event);
}
if (handled == false && mControllerMoga != null) {
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
}
if (handled == false && mControllerOuya != null) {
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
}
if (handled == false) {
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
}
return handled || super.dispatchGenericMotionEvent(event);
}
@Override
public void onInputDeviceAdded(int deviceId) {
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
mControllerHelper.onInputDeviceAdded(deviceId);
}
/*
* This is an unusual case. Input devices don't typically change, but they
* certainly can --- for example a device may have different modes. We use
* this to make sure that the ship has an up-to-date InputDevice.
*
* @see
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
* #onInputDeviceChanged(int)
*/
@Override
public void onInputDeviceChanged(int deviceId) {
Log.w(TAG,"onInputDeviceChanged:" + deviceId);
}
/*
* Remove any ship associated with the ID.
*
* @see
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
* #onInputDeviceRemoved(int)
*/
@Override
public void onInputDeviceRemoved(int deviceId) {
Log.d(TAG,"onInputDeviceRemoved:" + deviceId);
mControllerHelper.onInputDeviceRemoved(deviceId);
}
@Override
protected void onResume() {
super.onResume();
if (mControllerNibiru != null) {
mControllerNibiru.onResume();
}
if (mControllerMoga != null) {
mControllerMoga.onResume();
}
if (mControllerOuya != null) {
mControllerOuya.onResume();
}
GameControllerHelper.gatherControllers(mControllerHelper.mGameController);
}
@Override
protected void onPause() {
if (mControllerNibiru != null) {
mControllerNibiru.onPause();
}
if (mControllerMoga != null) {
mControllerMoga.onPause();
}
if (mControllerOuya != null) {
mControllerOuya.onPause();
}
super.onPause();
}
@Override
protected void onDestroy() {
if (mControllerNibiru != null) {
mControllerNibiru.onDestroy();
}
if (mControllerMoga != null) {
mControllerMoga.onDestroy();
}
if (mControllerOuya != null) {
mControllerOuya.onDestroy();
}
super.onDestroy();
}
}
@@ -1,283 +0,0 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.util.ArrayList;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
public class GameControllerHelper {
public static final String StandardControllerName = "Standard";
SparseIntArray ControllerKeyMap;
private static final int AXIS_X = 0;
private static final int AXIS_Y = 1;
private static final int AXIS_Z = 11;
private static final int AXIS_RZ = 14;
private static final int AXIS_LTRIGGER = 17;
private static final int AXIS_RTRIGGER = 18;
public static final int AXIS_GAS = 22;
private static final int AXIS_BRAKE = 23;
private static final int AXIS_THROTTLE = 19;
public GameControllerHelper(GameControllerActivity activity){
ControllerKeyMap = new SparseIntArray(25);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z);
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP);
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, GameControllerDelegate.BUTTON_DPAD_CENTER);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT);
}
private float mOldLeftThumbstickX = 0.0f;
private float mOldLeftThumbstickY = 0.0f;
private float mOldRightThumbstickX = 0.0f;
private float mOldRightThumbstickY = 0.0f;
private float mOldLeftTrigger = 0.0f;
private float mOldRightTrigger = 0.0f;
private float mOldThrottle = 0.0f;
private float mOldBrake = 0.0f;
private float mOldGas = 0.0f;
public boolean dispatchGenericMotionEvent(MotionEvent event) {
boolean handled = false;
int eventSource = event.getSource();
if ( ((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
if (event.getAction() == MotionEvent.ACTION_MOVE) {
int deviceId = event.getDeviceId();
String deviceName = event.getDevice().getName();
if(mGameController.get(deviceId) == null){
gatherControllers(mGameController);
mGameController.append(deviceId, deviceName);
}
float newAXIS_LX = event.getAxisValue(AXIS_X);
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
mOldLeftThumbstickX = newAXIS_LX;
handled = true;
}
float newAXIS_LY = event.getAxisValue(AXIS_Y);
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
mOldLeftThumbstickY = newAXIS_LY;
handled = true;
}
float newAXIS_RX = event.getAxisValue(AXIS_Z);
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
mOldRightThumbstickX = newAXIS_RX;
handled = true;
}
float newAXIS_RY = event.getAxisValue(AXIS_RZ);
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
mOldRightThumbstickY = newAXIS_RY;
handled = true;
}
float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER);
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true);
mOldLeftTrigger = newAXIS_LTRIGGER;
handled = true;
}
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true);
mOldRightTrigger = newAXIS_RTRIGGER;
handled = true;
}
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true);
mOldBrake = newAXIS_BRAKE;
handled = true;
}
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true);
mOldThrottle = newAXIS_THROTTLE;
handled = true;
}
float newAXIS_GAS = event.getAxisValue(AXIS_GAS);
if (Float.compare(newAXIS_GAS , mOldGas) != 0) {
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true);
mOldGas = newAXIS_GAS;
handled = true;
}
}
}
return handled;
}
private static SparseArray<ArrayList<Integer>> mControllerExtendKey = new SparseArray<ArrayList<Integer>>();
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
int eventSource = event.getSource();
int keyCode = event.getKeyCode();
int controllerKey = ControllerKeyMap.get(keyCode);
if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
int deviceId = event.getDeviceId();
String deviceName = event.getDevice().getName();
if(mGameController.get(deviceId) == null){
gatherControllers(mGameController);
mGameController.append(deviceId, deviceName);
}
if (controllerKey == 0) {
if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) {
controllerKey = keyCode;
}else {
return false;
}
}
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
handled = true;
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false);
}else if (action == KeyEvent.ACTION_UP) {
handled = true;
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false);
}
}
return handled;
}
public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) {
if (receive) {
if (mControllerExtendKey.get(deviceId) == null) {
mControllerExtendKey.put(deviceId, new ArrayList<Integer>());
}
mControllerExtendKey.get(deviceId).add(externalKeyCode);
} else {
if (mControllerExtendKey.get(deviceId) != null) {
mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode));
}
}
}
SparseArray<String> mGameController = new SparseArray<String>();
void onInputDeviceAdded(int deviceId){
try {
InputDevice device = InputDevice.getDevice(deviceId);
int deviceSource = device.getSources();
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
String deviceName = device.getName();
mGameController.append(deviceId, deviceName);
GameControllerAdapter.onConnected(deviceName, deviceId);
}
} catch (Exception e) {
e.printStackTrace();
}
}
void onInputDeviceChanged(int deviceId){
gatherControllers(mGameController);
}
void onInputDeviceRemoved(int deviceId) {
if (mGameController.get(deviceId) != null) {
GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId);
mGameController.delete(deviceId);
}
}
static void gatherControllers(SparseArray<String> controllers){
int controllerCount = controllers.size();
for (int i = 0; i < controllerCount; i++) {
try {
int controllerDeveceId = controllers.keyAt(i);
InputDevice device = InputDevice.getDevice(controllerDeveceId);
if (device == null) {
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
controllers.delete(controllerDeveceId);
}
} catch (Exception e) {
int controllerDeveceId = controllers.keyAt(i);
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
controllers.delete(controllerDeveceId);
e.printStackTrace();
}
}
}
}
@@ -1,244 +0,0 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import org.cocos2dx.lib.GameControllerDelegate;
import android.content.Context;
import android.os.Handler;
import android.util.SparseIntArray;
import com.bda.controller.Controller;
import com.bda.controller.ControllerListener;
import com.bda.controller.KeyEvent;
import com.bda.controller.MotionEvent;
import com.bda.controller.StateEvent;
public class GameControllerMoga implements ControllerListener, GameControllerDelegate {
private static final String mVendorName = "Moga";
private float mOldLeftThumbstickX = 0.0f;
private float mOldLeftThumbstickY = 0.0f;
private float mOldRightThumbstickX = 0.0f;
private float mOldRightThumbstickY = 0.0f;
private float mOldLeftTrigger = 0.0f;
private float mOldRightTrigger = 0.0f;
private SparseIntArray mKeyMap = null;
public GameControllerMoga() {
mKeyMap = new SparseIntArray(20);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1,
GameControllerDelegate.BUTTON_LEFT_SHOULDER);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1,
GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2,
GameControllerDelegate.BUTTON_LEFT_TRIGGER);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2,
GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
mKeyMap.put(KeyEvent.KEYCODE_DPAD_UP,
GameControllerDelegate.BUTTON_DPAD_UP);
mKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN,
GameControllerDelegate.BUTTON_DPAD_DOWN);
mKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT,
GameControllerDelegate.BUTTON_DPAD_LEFT);
mKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT,
GameControllerDelegate.BUTTON_DPAD_RIGHT);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
GameControllerDelegate.BUTTON_START);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT,
GameControllerDelegate.BUTTON_SELECT);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
GameControllerDelegate.BUTTON_START);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL,
GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR,
GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
}
public void onKeyEvent(KeyEvent event) {
int keycode = event.getKeyCode();
if (keycode == KeyEvent.KEYCODE_BUTTON_L2
|| keycode == KeyEvent.KEYCODE_BUTTON_R2) {
return;
}
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
boolean isAnalog = false;
if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL
|| keycode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
isAnalog = true;
}
if (mKeyMap.get(keycode, Integer.MIN_VALUE) != Integer.MIN_VALUE && mControllerEventListener != null) {
mControllerEventListener.onButtonEvent(mVendorName,
event.getControllerId(), mKeyMap.get(keycode), isPressed,
isPressed ? 1.0f : 0.0f, isAnalog);
}
}
@Override
public void onMotionEvent(MotionEvent event) {
if (mControllerEventListener == null) {
return;
}
int controllerId = event.getControllerId();
float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X);
if (newLeftThumbstickX != mOldLeftThumbstickX) {
mControllerEventListener.onAxisEvent(mVendorName,
controllerId,
GameControllerDelegate.THUMBSTICK_LEFT_X,
newLeftThumbstickX, true);
mOldLeftThumbstickX = newLeftThumbstickX;
}
float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y);
if (newLeftThumbstickY != mOldLeftThumbstickY) {
mControllerEventListener.onAxisEvent(mVendorName,
controllerId,
GameControllerDelegate.THUMBSTICK_LEFT_Y,
newLeftThumbstickY, true);
mOldLeftThumbstickY = newLeftThumbstickY;
}
float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z);
if (newRightThumbstickX != mOldRightThumbstickX) {
mControllerEventListener.onAxisEvent(mVendorName,
controllerId,
GameControllerDelegate.THUMBSTICK_RIGHT_X,
newRightThumbstickX, true);
mOldRightThumbstickX = newRightThumbstickX;
}
float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ);
if (newRightThumbstickY != mOldRightThumbstickY) {
mControllerEventListener.onAxisEvent(mVendorName,
controllerId,
GameControllerDelegate.THUMBSTICK_RIGHT_Y,
newRightThumbstickY, true);
mOldRightThumbstickY = newRightThumbstickY;
}
float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
if (newLeftTrigger != mOldLeftTrigger) {
mControllerEventListener.onAxisEvent(mVendorName,
controllerId,
GameControllerDelegate.BUTTON_LEFT_TRIGGER,
newLeftTrigger, true);
mOldLeftTrigger = newLeftTrigger;
}
float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
if (newRightTrigger != mOldRightTrigger) {
mControllerEventListener.onAxisEvent(mVendorName,
controllerId,
GameControllerDelegate.BUTTON_RIGHT_TRIGGER,
newRightTrigger, true);
mOldRightTrigger = newRightTrigger;
}
}
@Override
public void onStateEvent(StateEvent event) {
if (mControllerEventListener != null) {
switch (event.getState()) {
case StateEvent.STATE_CONNECTION:
switch (event.getAction()) {
case StateEvent.ACTION_DISCONNECTED:
// disconnected from controller
mControllerEventListener.onDisconnected(mVendorName,
event.getControllerId());
break;
case StateEvent.ACTION_CONNECTED:
// connected to controller
mControllerEventListener.onConnected(mVendorName,
event.getControllerId());
break;
case StateEvent.ACTION_CONNECTING:
// attempting to connect to controller
break;
}
break;
case StateEvent.STATE_POWER_LOW:
if (event.getAction() == StateEvent.ACTION_TRUE) {
// controller has entered low power state
} else {
// controller has entered normal power state
}
break;
}
}
}
private Controller mController = null;
public void onCreate(Context context) {
mController = Controller.getInstance(context);
mController.init();
mController.setListener(this, new Handler());
}
public void onPause() {
mController.onPause();
}
public void onResume() {
mController.onResume();
}
public void onDestroy() {
mController.exit();
}
private ControllerEventListener mControllerEventListener;
@Override
public void setControllerEventListener(ControllerEventListener listener) {
mControllerEventListener = listener;
}
@Override
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
return false;
}
@Override
public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) {
return false;
}
}
@@ -1,265 +0,0 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import org.cocos2dx.lib.GameControllerDelegate;
import com.nibiru.lib.controller.AccEvent;
import com.nibiru.lib.controller.Controller;
import com.nibiru.lib.controller.ControllerDevice;
import com.nibiru.lib.controller.ControllerKeyEvent;
import com.nibiru.lib.controller.ControllerService;
import com.nibiru.lib.controller.ControllerService.OnControllerSeviceListener;
import com.nibiru.lib.controller.ControllerServiceException;
import com.nibiru.lib.controller.GyroEvent;
import com.nibiru.lib.controller.OnAccListener;
import com.nibiru.lib.controller.OnGyroListener;
import com.nibiru.lib.controller.OnKeyListener;
import com.nibiru.lib.controller.OnSimpleStickListener;
import com.nibiru.lib.controller.OnStateListener;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.KeyEvent;
import android.view.MotionEvent;
public class GameControllerNibiru implements OnControllerSeviceListener, OnKeyListener,
OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameControllerDelegate {
private static final String TAG = "NibiruTag";
private Context mContext;
private SparseIntArray mKeyMap;
private ControllerEventListener mControllerEventListener = null;
private ControllerService mControllerService = null;
public GameControllerNibiru() {
mKeyMap = new SparseIntArray(20);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_A , GameControllerDelegate.BUTTON_A);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_B , GameControllerDelegate.BUTTON_B);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_X , GameControllerDelegate.BUTTON_X);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_Y , GameControllerDelegate.BUTTON_Y);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_L1 , GameControllerDelegate.BUTTON_LEFT_SHOULDER);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_R1 , GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
mKeyMap.put(ControllerKeyEvent.KEYCODE_UP , GameControllerDelegate.BUTTON_DPAD_UP);
mKeyMap.put(ControllerKeyEvent.KEYCODE_DOWN , GameControllerDelegate.BUTTON_DPAD_DOWN);
mKeyMap.put(ControllerKeyEvent.KEYCODE_LEFT , GameControllerDelegate.BUTTON_DPAD_LEFT);
mKeyMap.put(ControllerKeyEvent.KEYCODE_RIGHT , GameControllerDelegate.BUTTON_DPAD_RIGHT);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_START , GameControllerDelegate.BUTTON_START);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_SELECT , GameControllerDelegate.BUTTON_SELECT);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBL , GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBR , GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
}
@Override
public void setControllerEventListener(ControllerEventListener listener) {
mControllerEventListener = listener;
}
public void onCreate(Context context) {
mContext = context;
mControllerService = Controller.getControllerService(context);
if (mControllerService != null) {
mControllerService.setControllerServiceListener(this);
mControllerService.setStateListener(this);
mControllerService.setKeyListener(this);
mControllerService.setSimpleStickListener(this);
//mControllerService.setAccListener(this);
//mControllerService.setGyroListener(this);
mControllerService.setEnableL2R2(true);
mControllerService.setAutoKeyUpMode(false);
mControllerService.checkNibiruInstall(mContext, false);
}
}
public void onPause() {
if (mControllerService != null) {
mControllerService.setEnable(false);
}
}
public void onResume() {
if (mControllerService != null) {
if (mControllerService.isServiceEnable()) {
//onControllerServiceReady(true);
} else {
if (mControllerService.checkNibiruInstall(mContext, false)) {
try {
mControllerService.register(mContext);
} catch (ControllerServiceException e) {
e.printStackTrace();
}
}
}
mControllerService.setEnable(true);
}
}
public void onDestroy() {
if( mControllerService != null ){
mControllerService.unregister();
}
}
@Override
public void onControllerServiceReady(boolean isSucc) {
if( isSucc )
{
if( !mControllerService.hasDeviceConnected() ){
Bundle bun = new Bundle();
bun.putBoolean(ControllerService.FLAG_IS_SHOW_GAMEPAD_TIP, false);
/*try {
mControllerService.showDeviceManagerUI(mContext, bun);
} catch (ControllerServiceException e) {
e.printStackTrace();
}*/
}
}
}
@Override
public void onControllerKeyDown(int playerOrder, int keyCode, ControllerKeyEvent event) {
if (mKeyMap.get(keyCode) == 0) {
Log.e(TAG, "Didn't map the key: " + keyCode);
return;
}
if (mControllerEventListener != null) {
try {
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
mKeyMap.get(keyCode), true, 1.0f, false);
} catch (ControllerServiceException e) {
e.printStackTrace();
}
}
}
@Override
public void onControllerKeyUp(int playerOrder, int keyCode, ControllerKeyEvent event) {
if (mKeyMap.get(keyCode) == 0) {
Log.e(TAG, "Didn't map the key: " + keyCode);
return;
}
if (mControllerEventListener != null) {
try {
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
mKeyMap.get(keyCode), false, 0.0f, false);
} catch (ControllerServiceException e) {
e.printStackTrace();
}
}
}
@Override
public void onLeftStickChanged(int playerOrder, float x, float y) {
if (mControllerEventListener != null) {
try {
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
String deviceName = controllerDevice.getDeviceName();
int deviceId = controllerDevice.getDeviceId();
mControllerEventListener.onAxisEvent(deviceName, deviceId,
GameControllerDelegate.THUMBSTICK_LEFT_X, x, true);
mControllerEventListener.onAxisEvent(deviceName, deviceId,
GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true);
} catch (ControllerServiceException e) {
e.printStackTrace();
}
}
}
@Override
public void onRightStickChanged(int playerOrder, float x, float y) {
if (mControllerEventListener != null) {
try {
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
String deviceName = controllerDevice.getDeviceName();
int deviceId = controllerDevice.getDeviceId();
mControllerEventListener.onAxisEvent(deviceName, deviceId,
GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true);
mControllerEventListener.onAxisEvent(deviceName, deviceId,
GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true);
} catch (ControllerServiceException e) {
e.printStackTrace();
}
}
}
@Override
public void onControllerStateChanged(int playerOrder, int state, ControllerDevice device) {
if (mControllerEventListener != null) {
if (state == ControllerDevice.STATE_CONN)
{
mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId());
}
else if (state == ControllerDevice.STATE_DISCONN)
{
mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId());
}
}
}
public boolean dispatchGenericMotionEvent(MotionEvent event){
return mControllerService.handleExternalInput(event);
}
public boolean dispatchKeyEvent(KeyEvent event){
return mControllerService.handleExternalInput(event);
}
@Override
public void onControllerAccEvent(int playerOrder, AccEvent event) {
}
@Override
public void onControllerGyroEvent(int playerOrder, GyroEvent event) {
}
@Override
public void onBluetoothStateChanged(int state) {
Log.d(TAG, "onBluetoothStateChanged:"+state);
}
}
@@ -1,201 +0,0 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import org.cocos2dx.lib.GameControllerDelegate;
import tv.ouya.console.api.OuyaController;
import android.content.Context;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.KeyEvent;
import android.view.MotionEvent;
public class GameControllerOuya implements GameControllerDelegate{
private SparseIntArray mKeyMap;
private SparseArray<String> mGameController = new SparseArray<String>();
public GameControllerOuya(){
mKeyMap = new SparseIntArray(20);
mKeyMap.put(OuyaController.BUTTON_A, GameControllerDelegate.BUTTON_B);
mKeyMap.put(OuyaController.BUTTON_O, GameControllerDelegate.BUTTON_A);
mKeyMap.put(OuyaController.BUTTON_U, GameControllerDelegate.BUTTON_X);
mKeyMap.put(OuyaController.BUTTON_Y, GameControllerDelegate.BUTTON_Y);
mKeyMap.put(OuyaController.BUTTON_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
mKeyMap.put(OuyaController.BUTTON_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
mKeyMap.put(OuyaController.BUTTON_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
mKeyMap.put(OuyaController.BUTTON_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP);
mKeyMap.put(OuyaController.BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER);
mKeyMap.put(OuyaController.BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
mKeyMap.put(OuyaController.BUTTON_L3, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
mKeyMap.put(OuyaController.BUTTON_R3, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
}
public void onCreate(Context context) {
OuyaController.init(context);
}
private float mOldLeftThumbstickX = 0.0f;
private float mOldLeftThumbstickY = 0.0f;
private float mOldRightThumbstickX = 0.0f;
private float mOldRightThumbstickY = 0.0f;
private float mOldLeftTrigger = 0.0f;
private float mOldRightTrigger = 0.0f;
public boolean dispatchGenericMotionEvent(MotionEvent event) {
boolean handled = OuyaController.onGenericMotionEvent(event);
if (handled && mControllerEventListener != null)
{
int deviceId = event.getDeviceId();
String deviceName = event.getDevice().getName();
OuyaController c = OuyaController.getControllerByDeviceId(deviceId);
if (mGameController.get(deviceId) == null) {
GameControllerHelper.gatherControllers(mGameController);
mGameController.append(deviceId, deviceName);
}
float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2);
if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true);
mOldLeftTrigger = newLeftTrigger;
}
float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2);
if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true);
mOldRightTrigger = newRightTrigger;
}
float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X);
if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) {
if (Float.compare(newLeftThumbstickX, 0.0f) == 0) {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true);
}else {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true);
}
mOldLeftThumbstickX = newLeftThumbstickX;
}
float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y);
if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) {
if (Float.compare(newLeftThumbstickY, 0.0f) == 0) {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true);
}else {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true);
}
mOldLeftThumbstickY = newLeftThumbstickY;
}
float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X);
if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) {
if (Float.compare(newRightThumbstickX, 0.0f) == 0) {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true);
}else {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true);
}
mOldRightThumbstickX = newRightThumbstickX;
}
float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y);
if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) {
if (Float.compare(newRightThumbstickY, 0.0f) == 0) {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true);
}else {
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true);
}
mOldRightThumbstickY = newRightThumbstickY;
}
}
return handled;
}
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
int action = event.getAction();
int keyCode = event.getKeyCode();
if (action == KeyEvent.ACTION_DOWN) {
handled = OuyaController.onKeyDown(keyCode, event);
}
else if (action == KeyEvent.ACTION_UP) {
handled = OuyaController.onKeyUp(keyCode, event);
}
if (handled && mControllerEventListener != null) {
boolean isAnalog = false;
if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL || keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR){
isAnalog = true;
}
int deviceId = event.getDeviceId();
String deviceName = event.getDevice().getName();
if (mGameController.get(deviceId) == null) {
GameControllerHelper.gatherControllers(mGameController);
mGameController.append(deviceId, deviceName);
}
if (action == KeyEvent.ACTION_DOWN) {
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), true, 1.0f, isAnalog);
}else {
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), false, 0.0f, isAnalog);
}
}
return handled;
}
public void onPause() {
// show the mouse cursor
OuyaController.showCursor(true);
}
public void onResume() {
// hide the mouse cursor
OuyaController.showCursor(false);
}
public void onDestroy() {
}
private ControllerEventListener mControllerEventListener;
@Override
public void setControllerEventListener(ControllerEventListener listener) {
mControllerEventListener = listener;
}
}
@@ -1,141 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cocos2dx.lib.inputmanagercompat;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.view.InputDevice;
import android.view.MotionEvent;
public interface InputManagerCompat {
/**
* Gets information about the input device with the specified id.
*
* @param id The device id
* @return The input device or null if not found
*/
public InputDevice getInputDevice(int id);
/**
* Gets the ids of all input devices in the system.
*
* @return The input device ids.
*/
public int[] getInputDeviceIds();
/**
* Registers an input device listener to receive notifications about when
* input devices are added, removed or changed.
*
* @param listener The listener to register.
* @param handler The handler on which the listener should be invoked, or
* null if the listener should be invoked on the calling thread's
* looper.
*/
public void registerInputDeviceListener(InputManagerCompat.InputDeviceListener listener,
Handler handler);
/**
* Unregisters an input device listener.
*
* @param listener The listener to unregister.
*/
public void unregisterInputDeviceListener(InputManagerCompat.InputDeviceListener listener);
/*
* The following three calls are to simulate V16 behavior on pre-Jellybean
* devices. If you don't call them, your callback will never be called
* pre-API 16.
*/
/**
* Pass the motion events to the InputManagerCompat. This is used to
* optimize for polling for controllers. If you do not pass these events in,
* polling will cause regular object creation.
*
* @param event the motion event from the app
*/
public void onGenericMotionEvent(MotionEvent event);
/**
* Tell the V9 input manager that it should stop polling for disconnected
* devices. You can call this during onPause in your activity, although you
* might want to call it whenever your game is not active (or whenever you
* don't care about being notified of new input devices)
*/
public void onPause();
/**
* Tell the V9 input manager that it should start polling for disconnected
* devices. You can call this during onResume in your activity, although you
* might want to call it less often (only when the gameplay is actually
* active)
*/
public void onResume();
public interface InputDeviceListener {
/**
* Called whenever the input manager detects that a device has been
* added. This will only be called in the V9 version when a motion event
* is detected.
*
* @param deviceId The id of the input device that was added.
*/
void onInputDeviceAdded(int deviceId);
/**
* Called whenever the properties of an input device have changed since
* they were last queried. This will not be called for the V9 version of
* the API.
*
* @param deviceId The id of the input device that changed.
*/
void onInputDeviceChanged(int deviceId);
/**
* Called whenever the input manager detects that a device has been
* removed. For the V9 version, this can take some time depending on the
* poll rate.
*
* @param deviceId The id of the input device that was removed.
*/
void onInputDeviceRemoved(int deviceId);
}
/**
* Use this to construct a compatible InputManager.
*/
public static class Factory {
/**
* Constructs and returns a compatible InputManger
*
* @param context the Context that will be used to get the system
* service from
* @return a compatible implementation of InputManager
*/
public static InputManagerCompat getInputManager(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return new InputManagerV16(context);
} else {
return new InputManagerV9();
}
}
}
}
@@ -1,108 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cocos2dx.lib.inputmanagercompat;
import android.annotation.TargetApi;
import android.content.Context;
import android.hardware.input.InputManager;
import android.os.Build;
import android.os.Handler;
import android.view.InputDevice;
import android.view.MotionEvent;
import java.util.HashMap;
import java.util.Map;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class InputManagerV16 implements InputManagerCompat {
private final InputManager mInputManager;
private final Map<InputManagerCompat.InputDeviceListener, V16InputDeviceListener> mListeners;
public InputManagerV16(Context context) {
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
mListeners = new HashMap<InputManagerCompat.InputDeviceListener, V16InputDeviceListener>();
}
@Override
public InputDevice getInputDevice(int id) {
return mInputManager.getInputDevice(id);
}
@Override
public int[] getInputDeviceIds() {
return mInputManager.getInputDeviceIds();
}
static class V16InputDeviceListener implements InputManager.InputDeviceListener {
final InputManagerCompat.InputDeviceListener mIDL;
public V16InputDeviceListener(InputDeviceListener idl) {
mIDL = idl;
}
@Override
public void onInputDeviceAdded(int deviceId) {
mIDL.onInputDeviceAdded(deviceId);
}
@Override
public void onInputDeviceChanged(int deviceId) {
mIDL.onInputDeviceChanged(deviceId);
}
@Override
public void onInputDeviceRemoved(int deviceId) {
mIDL.onInputDeviceRemoved(deviceId);
}
}
@Override
public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
V16InputDeviceListener v16Listener = new V16InputDeviceListener(listener);
mInputManager.registerInputDeviceListener(v16Listener, handler);
mListeners.put(listener, v16Listener);
}
@Override
public void unregisterInputDeviceListener(InputDeviceListener listener) {
V16InputDeviceListener curListener = mListeners.remove(listener);
if (null != curListener)
{
mInputManager.unregisterInputDeviceListener(curListener);
}
}
@Override
public void onGenericMotionEvent(MotionEvent event) {
// unused in V16
}
@Override
public void onPause() {
// unused in V16
}
@Override
public void onResume() {
// unused in V16
}
}
@@ -1,212 +0,0 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cocos2dx.lib.inputmanagercompat;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseArray;
import android.view.InputDevice;
import android.view.MotionEvent;
import java.lang.ref.WeakReference;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
public class InputManagerV9 implements InputManagerCompat {
private static final String LOG_TAG = "InputManagerV9";
private static final int MESSAGE_TEST_FOR_DISCONNECT = 101;
private static final long CHECK_ELAPSED_TIME = 3000L;
private static final int ON_DEVICE_ADDED = 0;
private static final int ON_DEVICE_CHANGED = 1;
private static final int ON_DEVICE_REMOVED = 2;
private final SparseArray<long[]> mDevices;
private final Map<InputDeviceListener, Handler> mListeners;
private final Handler mDefaultHandler;
private static class PollingMessageHandler extends Handler {
private final WeakReference<InputManagerV9> mInputManager;
PollingMessageHandler(InputManagerV9 im) {
mInputManager = new WeakReference<InputManagerV9>(im);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case MESSAGE_TEST_FOR_DISCONNECT:
InputManagerV9 imv = mInputManager.get();
if (null != imv) {
long time = SystemClock.elapsedRealtime();
int size = imv.mDevices.size();
for (int i = 0; i < size; i++) {
long[] lastContact = imv.mDevices.valueAt(i);
if (null != lastContact) {
if (time - lastContact[0] > CHECK_ELAPSED_TIME) {
// check to see if the device has been
// disconnected
int id = imv.mDevices.keyAt(i);
if (null == InputDevice.getDevice(id)) {
// disconnected!
imv.notifyListeners(ON_DEVICE_REMOVED, id);
imv.mDevices.remove(id);
} else {
lastContact[0] = time;
}
}
}
}
sendEmptyMessageDelayed(MESSAGE_TEST_FOR_DISCONNECT,
CHECK_ELAPSED_TIME);
}
break;
}
}
}
public InputManagerV9() {
mDevices = new SparseArray<long[]>();
mListeners = new HashMap<InputDeviceListener, Handler>();
mDefaultHandler = new PollingMessageHandler(this);
// as a side-effect, populates our collection of watched
// input devices
getInputDeviceIds();
}
@Override
public InputDevice getInputDevice(int id) {
return InputDevice.getDevice(id);
}
@Override
public int[] getInputDeviceIds() {
// add any hitherto unknown devices to our
// collection of watched input devices
int[] activeDevices = InputDevice.getDeviceIds();
long time = SystemClock.elapsedRealtime();
for ( int id : activeDevices ) {
long[] lastContact = mDevices.get(id);
if ( null == lastContact ) {
// we have a new device
mDevices.put(id, new long[] { time });
}
}
return activeDevices;
}
@Override
public void registerInputDeviceListener(InputDeviceListener listener, Handler handler) {
mListeners.remove(listener);
if (handler == null) {
handler = mDefaultHandler;
}
mListeners.put(listener, handler);
}
@Override
public void unregisterInputDeviceListener(InputDeviceListener listener) {
mListeners.remove(listener);
}
private void notifyListeners(int why, int deviceId) {
// the state of some device has changed
if (!mListeners.isEmpty()) {
// yes... this will cause an object to get created... hopefully
// it won't happen very often
for (InputDeviceListener listener : mListeners.keySet()) {
Handler handler = mListeners.get(listener);
DeviceEvent odc = DeviceEvent.getDeviceEvent(why, deviceId, listener);
handler.post(odc);
}
}
}
private static class DeviceEvent implements Runnable {
private int mMessageType;
private int mId;
private InputDeviceListener mListener;
private static Queue<DeviceEvent> sEventQueue = new ArrayDeque<DeviceEvent>();
private DeviceEvent() {
}
static DeviceEvent getDeviceEvent(int messageType, int id,
InputDeviceListener listener) {
DeviceEvent curChanged = sEventQueue.poll();
if (null == curChanged) {
curChanged = new DeviceEvent();
}
curChanged.mMessageType = messageType;
curChanged.mId = id;
curChanged.mListener = listener;
return curChanged;
}
@Override
public void run() {
switch (mMessageType) {
case ON_DEVICE_ADDED:
mListener.onInputDeviceAdded(mId);
break;
case ON_DEVICE_CHANGED:
mListener.onInputDeviceChanged(mId);
break;
case ON_DEVICE_REMOVED:
mListener.onInputDeviceRemoved(mId);
break;
default:
Log.e(LOG_TAG, "Unknown Message Type");
break;
}
// dump this runnable back in the queue
sEventQueue.offer(this);
}
}
@Override
public void onGenericMotionEvent(MotionEvent event) {
// detect new devices
int id = event.getDeviceId();
long[] timeArray = mDevices.get(id);
if (null == timeArray) {
notifyListeners(ON_DEVICE_ADDED, id);
timeArray = new long[1];
mDevices.put(id, timeArray);
}
long time = SystemClock.elapsedRealtime();
timeArray[0] = time;
}
@Override
public void onPause() {
mDefaultHandler.removeMessages(MESSAGE_TEST_FOR_DISCONNECT);
}
@Override
public void onResume() {
mDefaultHandler.sendEmptyMessage(MESSAGE_TEST_FOR_DISCONNECT);
}
}
@@ -1,103 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.util.ArrayList;
public class GameControllerAdapter {
private static ArrayList<Runnable> sRunnableFrameStartList = null;
public static void addRunnableToFrameStartList(Runnable runnable) {
if (sRunnableFrameStartList == null)
sRunnableFrameStartList = new ArrayList<Runnable>();
sRunnableFrameStartList.add(runnable);
}
public static void removeRunnableFromFrameStartList(Runnable runnable) {
if (sRunnableFrameStartList != null)
sRunnableFrameStartList.remove(runnable);
}
public static void onDrawFrameStart() {
if (sRunnableFrameStartList != null)
{
int size = sRunnableFrameStartList.size();
for (int i = 0; i < size; ++i) {
sRunnableFrameStartList.get(i).run();
}
}
}
public static void onConnected(final String vendorName, final int controller)
{
Cocos2dxHelper.runOnGLThread(new Runnable() {
@Override
public void run() {
nativeControllerConnected(vendorName, controller);
}
});
}
public static void onDisconnected(final String vendorName, final int controller)
{
Cocos2dxHelper.runOnGLThread(new Runnable() {
@Override
public void run() {
nativeControllerDisconnected(vendorName, controller);
}
});
}
public static void onButtonEvent(final String vendorName, final int controller, final int button, final boolean isPressed, final float value, final boolean isAnalog)
{
Cocos2dxHelper.runOnGLThread(new Runnable() {
@Override
public void run() {
nativeControllerButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
}
});
}
public static void onAxisEvent(final String vendorName, final int controller, final int axisID, final float value, final boolean isAnalog)
{
Cocos2dxHelper.runOnGLThread(new Runnable() {
@Override
public void run() {
nativeControllerAxisEvent(vendorName, controller, axisID, value, isAnalog);
}
});
}
private static native void nativeControllerConnected(final String vendorName, final int controller);
private static native void nativeControllerDisconnected(final String vendorName, final int controller);
private static native void nativeControllerButtonEvent(final String vendorName, final int controller, final int button, final boolean isPressed, final float value, final boolean isAnalog);
private static native void nativeControllerAxisEvent(final String vendorName, final int controller, final int axisID, final float value, final boolean isAnalog);
}
@@ -1,83 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import android.content.Context;
import android.view.KeyEvent;
import android.view.MotionEvent;
public interface GameControllerDelegate {
static final int KEY_BASE = 1000;
public static final int THUMBSTICK_LEFT_X = KEY_BASE;
public static final int THUMBSTICK_LEFT_Y = KEY_BASE + 1;
public static final int THUMBSTICK_RIGHT_X = KEY_BASE + 2;
public static final int THUMBSTICK_RIGHT_Y = KEY_BASE + 3;
public static final int BUTTON_A = KEY_BASE + 4;
public static final int BUTTON_B = KEY_BASE + 5;
public static final int BUTTON_C = KEY_BASE + 6;
public static final int BUTTON_X = KEY_BASE + 7;
public static final int BUTTON_Y = KEY_BASE + 8;
public static final int BUTTON_Z = KEY_BASE + 9;
public static final int BUTTON_DPAD_UP = KEY_BASE + 10;
public static final int BUTTON_DPAD_DOWN = KEY_BASE + 11;
public static final int BUTTON_DPAD_LEFT = KEY_BASE + 12;
public static final int BUTTON_DPAD_RIGHT = KEY_BASE + 13;
public static final int BUTTON_DPAD_CENTER = KEY_BASE + 14;
public static final int BUTTON_LEFT_SHOULDER = KEY_BASE + 15;
public static final int BUTTON_RIGHT_SHOULDER = KEY_BASE + 16;
public static final int BUTTON_LEFT_TRIGGER = KEY_BASE + 17;
public static final int BUTTON_RIGHT_TRIGGER = KEY_BASE + 18;
public static final int BUTTON_LEFT_THUMBSTICK = KEY_BASE + 19;
public static final int BUTTON_RIGHT_THUMBSTICK = KEY_BASE + 20;
public static final int BUTTON_START = KEY_BASE + 21;
public static final int BUTTON_SELECT = KEY_BASE + 22;
void onCreate(Context context);
void onPause();
void onResume();
void onDestroy();
boolean dispatchKeyEvent(KeyEvent event);
boolean dispatchGenericMotionEvent(MotionEvent event);
void setControllerEventListener(ControllerEventListener listener);
public interface ControllerEventListener {
void onButtonEvent(String vendorName, int controller, int button, boolean isPressed, float value, boolean isAnalog);
void onAxisEvent(String vendorName, int controller, int axisID, float value, boolean isAnalog);
void onConnected(String vendorName, int controller);
void onDisconnected(String vendorName, int controller);
}
}
@@ -1,69 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.io.File;
import java.io.FileInputStream;
public class GameControllerUtils {
public static void ensureDirectoryExist(String path){
File sdkDir = new File(path);
if(!sdkDir.exists()){
sdkDir.mkdirs();
}
}
public static String readJsonFile(String filePath) {
File file = new File(filePath);
if (!file.exists()){
return null;
}
try {
FileInputStream is = new FileInputStream(file);;
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String jsonstr = new String(buffer, "UTF-8");
return jsonstr;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
@@ -1,135 +0,0 @@
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
#include "base/CCEventCustom.h"
#include "base/CCEventType.h"
#include "platform/android/jni/JniHelper.h"
#include "network/CCDownloader-android.h"
#include <android/log.h>
#include <android/api-level.h>
#include <jni.h>
#define LOG_TAG "main"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
void cocos_android_app_init(JNIEnv* env) __attribute__((weak));
void cocos_audioengine_focus_change(int focusChange);
using namespace cocos2d;
extern "C"
{
// ndk break compatibility, refer to https://github.com/cocos2d/cocos2d-x/issues/16267 for detail information
// should remove it when using NDK r13 since NDK r13 will add back bsd_signal()
#if __ANDROID_API__ > 19
#include <signal.h>
#include <dlfcn.h>
typedef __sighandler_t (*bsd_signal_func_t)(int, __sighandler_t);
bsd_signal_func_t bsd_signal_func = NULL;
__sighandler_t bsd_signal(int s, __sighandler_t f) {
if (bsd_signal_func == NULL) {
// For now (up to Android 7.0) this is always available
bsd_signal_func = (bsd_signal_func_t) dlsym(RTLD_DEFAULT, "bsd_signal");
if (bsd_signal_func == NULL) {
__android_log_assert("", "bsd_signal_wrapper", "bsd_signal symbol not found!");
}
}
return bsd_signal_func(s, f);
}
#endif // __ANDROID_API__ > 19
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
JniHelper::setJavaVM(vm);
cocos_android_app_init(JniHelper::getEnv());
return JNI_VERSION_1_4;
}
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
// auto director = cocos2d::Director::getInstance();
// auto glview = director->getOpenGLView();
// if (!glview)
// {
// glview = cocos2d::GLViewImpl::create("Android app");
// glview->setFrameSize(w, h);
// director->setOpenGLView(glview);
// cocos2d::Application::getInstance()->run();
// }
// else
// {
// cocos2d::GL::invalidateStateCache();
// cocos2d::GLProgramCache::getInstance()->reloadDefaultGLPrograms();
// cocos2d::DrawPrimitives::init();
// cocos2d::VolatileTextureMgr::reloadAllTextures();
// cocos2d::EventCustom* recreatedEvent = new (std::nothrow) cocos2d::EventCustom(EVENT_RENDERER_RECREATED);
// director->getEventDispatcher()->dispatchEvent(recreatedEvent);
// recreatedEvent->release();
// director->setGLDefaultValues();
// }
// cocos2d::network::_preloadJavaDownloaderClass();
}
JNIEXPORT jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env, jobject thiz)
{
// cocos2d::Application::getInstance()->initGLContextAttrs();
// GLContextAttrs _glContextAttrs = GLView::getGLContextAttrs();
// int tmp[6] = {_glContextAttrs.redBits, _glContextAttrs.greenBits, _glContextAttrs.blueBits,
// _glContextAttrs.alphaBits, _glContextAttrs.depthBits, _glContextAttrs.stencilBits};
// jintArray glContextAttrsJava = env->NewIntArray(6);
// env->SetIntArrayRegion(glContextAttrsJava, 0, 6, tmp);
// return glContextAttrsJava;
}
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxAudioFocusManager_nativeOnAudioFocusChange(JNIEnv* env, jobject thiz, jint focusChange)
{
// cocos_audioengine_focus_change(focusChange);
}
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h)
{
// cocos2d::Application::getInstance()->applicationScreenSizeChanged(w, h);
}
}
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
@@ -1,43 +0,0 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "platform/android/jni/JniHelper.h"
#include <string.h>
#include "platform/CCFileUtils.h"
#include "base/ccUTF8.h"
static const std::string className = "org/cocos2dx/lib/Cocos2dxBitmap";
using namespace cocos2d;
int getFontSizeAccordingHeightJni(int height) {
return JniHelper::callStaticIntMethod(className, "getFontSizeAccordingHeight", height);
}
std::string getStringWithEllipsisJni(const char* text, float width, float fontSize) {
return JniHelper::callStaticStringMethod(className, "getStringWithEllipsis", text, width, fontSize);
}
@@ -1,35 +0,0 @@
/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __EDITBOX_JNI_H__
#define __EDITBOX_JNI_H__
#include <string>
int getFontSizeAccordingHeightJni(int height);
std::string getStringWithEllipsisJni(const char* text, float width, float fontSize);
#endif // __EDITBOX_JNI_H__
@@ -1,155 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include <stdlib.h>
#include <jni.h>
#include <android/log.h>
#include <string>
#include "platform/android/jni/JniHelper.h"
#include "platform/android/CCFileUtils-android.h"
#include "android/asset_manager_jni.h"
#include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
#include "base/ccUTF8.h"
#define LOG_TAG "Java_org_cocos2dx_lib_Cocos2dxHelper.cpp"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
static const std::string className = "org/cocos2dx/lib/Cocos2dxHelper";
static EditTextCallback s_editTextCallback = nullptr;
static void* s_ctx = nullptr;
static int __deviceSampleRate = 44100;
static int __deviceAudioBufferSizeInFrames = 192;
using namespace cocos2d;
using namespace std;
string g_apkPath;
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetApkPath(JNIEnv* env, jobject thiz, jstring apkPath) {
g_apkPath = JniHelper::jstring2string(apkPath);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetContext(JNIEnv* env, jobject thiz, jobject context, jobject assetManager) {
JniHelper::setClassLoaderFrom(context);
FileUtilsAndroid::setassetmanager(AAssetManager_fromJava(env, assetManager));
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetAudioDeviceInfo(JNIEnv* env, jobject thiz, jboolean isSupportLowLatency, jint deviceSampleRate, jint deviceAudioBufferSizeInFrames) {
__deviceSampleRate = deviceSampleRate;
__deviceAudioBufferSizeInFrames = deviceAudioBufferSizeInFrames;
LOGD("nativeSetAudioDeviceInfo: sampleRate: %d, bufferSizeInFrames: %d", __deviceSampleRate, __deviceAudioBufferSizeInFrames);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetEditTextDialogResult(JNIEnv* env, jobject obj, jbyteArray text) {
jsize size = env->GetArrayLength(text);
if (size > 0) {
jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0);
char* buffer = (char*)malloc(size+1);
if (buffer != nullptr) {
memcpy(buffer, data, size);
buffer[size] = '\0';
// pass data to edittext's delegate
if (s_editTextCallback) s_editTextCallback(buffer, s_ctx);
free(buffer);
}
env->ReleaseByteArrayElements(text, data, 0);
} else {
if (s_editTextCallback) s_editTextCallback("", s_ctx);
}
}
}
const char * getApkPath() {
return g_apkPath.c_str();
}
std::string getPackageNameJNI() {
return JniHelper::callStaticStringMethod(className, "getCocos2dxPackageName");
}
int getObbAssetFileDescriptorJNI(const char* path, long* startOffset, long* size) {
JniMethodInfo methodInfo;
int fd = 0;
if (JniHelper::getStaticMethodInfo(methodInfo, className.c_str(), "getObbAssetFileDescriptor", "(Ljava/lang/String;)[J")) {
jstring stringArg = methodInfo.env->NewStringUTF(path);
jlongArray newArray = (jlongArray)methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID, stringArg);
jsize theArrayLen = methodInfo.env->GetArrayLength(newArray);
if (theArrayLen == 3) {
jboolean copy = JNI_FALSE;
jlong *array = methodInfo.env->GetLongArrayElements(newArray, &copy);
fd = static_cast<int>(array[0]);
*startOffset = array[1];
*size = array[2];
methodInfo.env->ReleaseLongArrayElements(newArray, array, 0);
}
methodInfo.env->DeleteLocalRef(methodInfo.classID);
methodInfo.env->DeleteLocalRef(stringArg);
}
return fd;
}
int getDeviceSampleRate()
{
return __deviceSampleRate;
}
int getDeviceAudioBufferSizeInFrames()
{
return __deviceAudioBufferSizeInFrames;
}
void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharset, char* dst, const char* newCharset)
{
JniMethodInfo methodInfo;
if (JniHelper::getStaticMethodInfo(methodInfo, className.c_str(), "conversionEncoding", "([BLjava/lang/String;Ljava/lang/String;)[B")) {
jbyteArray strArray = methodInfo.env->NewByteArray(byteSize);
methodInfo.env->SetByteArrayRegion(strArray, 0, byteSize, reinterpret_cast<const jbyte*>(src));
jstring stringArg1 = methodInfo.env->NewStringUTF(fromCharset);
jstring stringArg2 = methodInfo.env->NewStringUTF(newCharset);
jbyteArray newArray = (jbyteArray)methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID, strArray, stringArg1, stringArg2);
jsize theArrayLen = methodInfo.env->GetArrayLength(newArray);
methodInfo.env->GetByteArrayRegion(newArray, 0, theArrayLen, (jbyte*)dst);
methodInfo.env->DeleteLocalRef(strArray);
methodInfo.env->DeleteLocalRef(stringArg1);
methodInfo.env->DeleteLocalRef(stringArg2);
methodInfo.env->DeleteLocalRef(newArray);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
}
@@ -1,41 +0,0 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __Java_org_cocos2dx_lib_Cocos2dxHelper_H__
#define __Java_org_cocos2dx_lib_Cocos2dxHelper_H__
#include <string>
typedef void (*EditTextCallback)(const char* text, void* ctx);
extern const char * getApkPath();
extern std::string getPackageNameJNI();
extern int getObbAssetFileDescriptorJNI(const char* path, long* startOffset, long* size);
extern void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharset, char* dst, const char* newCharset);
extern int getDeviceSampleRate();
extern int getDeviceAudioBufferSizeInFrames();
#endif /* __Java_org_cocos2dx_lib_Cocos2dxHelper_H__ */
@@ -1,87 +0,0 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "base/CCIMEDispatcher.h"
#include "base/CCEventType.h"
#include "base/CCEventCustom.h"
#include "platform/CCFileUtils.h"
#include "platform/android/jni/JniHelper.h"
#include <jni.h>
#include "base/ccUTF8.h"
using namespace cocos2d;
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env) {
// cocos2d::Director::getInstance()->mainLoop();
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause() {
// if (Director::getInstance()->getOpenGLView()) {
// Application::getInstance()->applicationDidEnterBackground();
// cocos2d::EventCustom* backgroundEvent = new (std::nothrow) cocos2d::EventCustom(EVENT_COME_TO_BACKGROUND);
// cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(backgroundEvent);
// backgroundEvent->release();
// }
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume() {
// static bool firstTime = true;
// if (Director::getInstance()->getOpenGLView()) {
// // don't invoke at first to keep the same logic as iOS
// // can refer to https://github.com/cocos2d/cocos2d-x/issues/14206
// if (!firstTime)
// Application::getInstance()->applicationWillEnterForeground();
// cocos2d::EventCustom* foregroundEvent = new (std::nothrow) cocos2d::EventCustom(EVENT_COME_TO_FOREGROUND);
// cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(foregroundEvent);
// foregroundEvent->release();
// firstTime = false;
// }
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInsertText(JNIEnv* env, jobject thiz, jstring text) {
// std::string strValue = cocos2d::StringUtils::getStringUTFCharsJNI(env, text);
// const char* pszText = strValue.c_str();
// cocos2d::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText));
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeDeleteBackward(JNIEnv* env, jobject thiz) {
// cocos2d::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
}
JNIEXPORT jstring JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeGetContentText() {
// JNIEnv * env = 0;
// if (JniHelper::getJavaVM()->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK || ! env) {
// return 0;
// }
// std::string pszText = cocos2d::IMEDispatcher::sharedDispatcher()->getContentText();
// return cocos2d::StringUtils::newStringUTFJNI(env, pszText);
}
}
@@ -0,0 +1,397 @@
/****************************************************************************
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "JniImp.h"
#include <unordered_map>
#include <android/log.h>
#include <android/asset_manager_jni.h>
#include <jni.h>
#include "JniHelper.h"
#include "platform/CCApplication.h"
#include "scripting/js-bindings/jswrapper/v8/ScriptEngine.hpp"
#include "scripting/js-bindings/event/EventDispatcher.h"
#include "platform/android/CCFileUtils-android.h"
#define JNI_IMP_LOG_TAG "JniImp"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,JNI_IMP_LOG_TAG,__VA_ARGS__)
#define KEYCODE_BACK 0x04
#define KEYCODE_MENU 0x52
#define KEYCODE_DPAD_UP 0x13
#define KEYCODE_DPAD_DOWN 0x14
#define KEYCODE_DPAD_LEFT 0x15
#define KEYCODE_DPAD_RIGHT 0x16
#define KEYCODE_ENTER 0x42
#define KEYCODE_PLAY 0x7e
#define KEYCODE_DPAD_CENTER 0x17
using namespace cocos2d;
namespace
{
// std::unordered_map<int, cocos2d::EventKeyboard::KeyCode> g_keyCodeMap =
// {
// { KEYCODE_BACK , cocos2d::EventKeyboard::KeyCode::KEY_ESCAPE },
// { KEYCODE_MENU , cocos2d::EventKeyboard::KeyCode::KEY_MENU },
// { KEYCODE_DPAD_UP , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_UP },
// { KEYCODE_DPAD_DOWN , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_DOWN },
// { KEYCODE_DPAD_LEFT , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_LEFT },
// { KEYCODE_DPAD_RIGHT , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_RIGHT },
// { KEYCODE_ENTER , cocos2d::EventKeyboard::KeyCode::KEY_ENTER },
// { KEYCODE_PLAY , cocos2d::EventKeyboard::KeyCode::KEY_PLAY },
// { KEYCODE_DPAD_CENTER , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_CENTER },
// };
std::string g_apkPath;
const std::string Cocos2dxHelperClassName = "org/cocos2dx/lib/Cocos2dxHelper";
const std::string Cocos2dxBitmapClassName = "org/cocos2dx/lib/Cocos2dxBitmap";
const std::string Cocos2dxRendererClassName = "org/cocos2dx/lib/Cocos2dxRenderer";
EditTextCallback s_editTextCallback = nullptr;
void* s_ctx = nullptr;
int g_deviceSampleRate = 44100;
int g_deviceAudioBufferSizeInFrames = 192;
int g_width = 0;
int g_height = 0;
cocos2d::Application* g_app = nullptr;
bool setCanvasCallback(se::Object* global)
{
se::AutoHandleScope scope;
se::ScriptEngine* se = se::ScriptEngine::getInstance();
char commandBuf[200] = {0};
sprintf(commandBuf, "var window = window || this; window.canvas = { width: %d, height: %d };",
g_width,
g_height);
se->evalString(commandBuf);
return true;
}
}
Application* cocos_android_app_init(JNIEnv* env);
extern "C"
{
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
JniHelper::setJavaVM(vm);
g_app = cocos_android_app_init(JniHelper::getEnv());
return JNI_VERSION_1_4;
}
/*****************************************************
* Cocos2dxActivity native functions implementation.
*****************************************************/
JNIEXPORT jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env, jobject thiz)
{
//TODO
int tmp[7] = {8, 8, 8,
8, 0, 0, 0};
jintArray glContextAttrsJava = env->NewIntArray(7);
env->SetIntArrayRegion(glContextAttrsJava, 0, 7, tmp);
return glContextAttrsJava;
}
/*****************************************************
* Cocos2dxRenderer native functions implementation.
*****************************************************/
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
g_width = w;
g_height = h;
se::ScriptEngine* se = se::ScriptEngine::getInstance();
se->addRegisterCallback(setCanvasCallback);
g_app->start();
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender(JNIEnv* env)
{
EventDispatcher::dispatchTickEvent();
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnPause()
{
if (g_app)
g_app->applicationDidEnterBackground();
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume()
{
if (g_app)
g_app->applicationWillEnterForeground();
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInsertText(JNIEnv* env, jobject thiz, jstring text)
{
//TODO
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeDeleteBackward(JNIEnv* env, jobject thiz)
{
//TODO
}
JNIEXPORT jstring JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeGetContentText()
{
//TODO
}
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnSurfaceChanged(JNIEnv* env, jobject thiz, jint w, jint h)
{
//TODO
}
/***********************************************************
* Cocos2dxAccelerometer native functions implementation.
***********************************************************/
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxAccelerometer_onSensorChanged(JNIEnv* env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp)
{
//TODO
}
/***********************************************************
* Touches native functions implementation.
***********************************************************/
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesBegin(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y)
{
//TODO
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y)
{
//TODO
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesMove(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
{
int size = env->GetArrayLength(ids);
jint id[size];
jfloat x[size];
jfloat y[size];
env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, x);
env->GetFloatArrayRegion(ys, 0, size, y);
intptr_t idlong[size];
for(int i = 0; i < size; i++)
idlong[i] = id[i];
//TODO
// cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(size, idlong, x, y);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesCancel(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
{
int size = env->GetArrayLength(ids);
jint id[size];
jfloat x[size];
jfloat y[size];
env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, x);
env->GetFloatArrayRegion(ys, 0, size, y);
intptr_t idlong[size];
for(int i = 0; i < size; i++)
idlong[i] = id[i];
//TODO
// cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(size, idlong, x, y);
}
JNIEXPORT jboolean JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyEvent(JNIEnv * env, jobject thiz, jint keyCode, jboolean isPressed)
{
//TODO
return JNI_TRUE;
}
/***********************************************************
* Cocos2dxHelper native functions implementation.
***********************************************************/
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetApkPath(JNIEnv* env, jobject thiz, jstring apkPath)
{
g_apkPath = JniHelper::jstring2string(apkPath);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetContext(JNIEnv* env, jobject thiz, jobject context, jobject assetManager)
{
JniHelper::setClassLoaderFrom(context);
FileUtilsAndroid::setassetmanager(AAssetManager_fromJava(env, assetManager));
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetAudioDeviceInfo(JNIEnv* env, jobject thiz, jboolean isSupportLowLatency, jint deviceSampleRate, jint deviceAudioBufferSizeInFrames)
{
g_deviceSampleRate = deviceSampleRate;
g_deviceAudioBufferSizeInFrames = deviceAudioBufferSizeInFrames;
LOGD("nativeSetAudioDeviceInfo: sampleRate: %d, bufferSizeInFrames: %d", g_deviceSampleRate, g_deviceAudioBufferSizeInFrames);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxHelper_nativeSetEditTextDialogResult(JNIEnv* env, jobject obj, jbyteArray text)
{
jsize size = env->GetArrayLength(text);
if (size > 0)
{
jbyte * data = (jbyte*)env->GetByteArrayElements(text, 0);
char* buffer = (char*)malloc(size+1);
if (buffer != nullptr)
{
memcpy(buffer, data, size);
buffer[size] = '\0';
// pass data to edittext's delegate
if (s_editTextCallback)
s_editTextCallback(buffer, s_ctx);
free(buffer);
}
env->ReleaseByteArrayElements(text, data, 0);
}
else
{
if (s_editTextCallback)
s_editTextCallback("", s_ctx);
}
}
/***********************************************************
* Cocos2dxAudioFocusManager native functions implementation.
***********************************************************/
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxAudioFocusManager_nativeOnAudioFocusChange(JNIEnv* env, jobject thiz, jint focusChange)
{
// cocos_audioengine_focus_change(focusChange);
}
} // end of extern "C"
/***********************************************************
* Functions invoke from cpp to Java.
***********************************************************/
std::string getApkPathJNI()
{
return g_apkPath;
}
std::string getPackageNameJNI()
{
return JniHelper::callStaticStringMethod(Cocos2dxHelperClassName, "getCocos2dxPackageName");
}
int getObbAssetFileDescriptorJNI(const std::string& path, long* startOffset, long* size)
{
JniMethodInfo methodInfo;
int fd = 0;
if (JniHelper::getStaticMethodInfo(methodInfo, Cocos2dxHelperClassName.c_str(), "getObbAssetFileDescriptor", "(Ljava/lang/String;)[J"))
{
jstring stringArg = methodInfo.env->NewStringUTF(path.c_str());
jlongArray newArray = (jlongArray)methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID, stringArg);
jsize theArrayLen = methodInfo.env->GetArrayLength(newArray);
if (3 == theArrayLen)
{
jboolean copy = JNI_FALSE;
jlong *array = methodInfo.env->GetLongArrayElements(newArray, &copy);
fd = static_cast<int>(array[0]);
*startOffset = array[1];
*size = array[2];
methodInfo.env->ReleaseLongArrayElements(newArray, array, 0);
}
methodInfo.env->DeleteLocalRef(methodInfo.classID);
methodInfo.env->DeleteLocalRef(stringArg);
}
return fd;
}
int getDeviceSampleRate()
{
return g_deviceSampleRate;
}
int getDeviceAudioBufferSizeInFrames()
{
return g_deviceAudioBufferSizeInFrames;
}
void convertEncodingJNI(const std::string& src, int byteSize, const std::string& fromCharset, std::string& dst, const std::string& newCharset)
{
JniMethodInfo methodInfo;
if (JniHelper::getStaticMethodInfo(methodInfo, Cocos2dxHelperClassName.c_str(), "conversionEncoding", "([BLjava/lang/String;Ljava/lang/String;)[B"))
{
jbyteArray strArray = methodInfo.env->NewByteArray(byteSize);
methodInfo.env->SetByteArrayRegion(strArray, 0, byteSize, reinterpret_cast<const jbyte*>(src.c_str()));
jstring stringArg1 = methodInfo.env->NewStringUTF(fromCharset.c_str());
jstring stringArg2 = methodInfo.env->NewStringUTF(newCharset.c_str());
jbyteArray newArray = (jbyteArray)methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID, strArray, stringArg1, stringArg2);
jsize theArrayLen = methodInfo.env->GetArrayLength(newArray);
methodInfo.env->GetByteArrayRegion(newArray, 0, theArrayLen, (jbyte*)dst.c_str());
methodInfo.env->DeleteLocalRef(strArray);
methodInfo.env->DeleteLocalRef(stringArg1);
methodInfo.env->DeleteLocalRef(stringArg2);
methodInfo.env->DeleteLocalRef(newArray);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
}
int getFontSizeAccordingHeightJni(int height)
{
return JniHelper::callStaticIntMethod(Cocos2dxBitmapClassName, "getFontSizeAccordingHeight", height);
}
std::string getStringWithEllipsisJni(const std::string& text, float width, float fontSize)
{
return JniHelper::callStaticStringMethod(Cocos2dxBitmapClassName, "getStringWithEllipsis", text.c_str(), width, fontSize);
}
std::string getCurrentLanguageJNI()
{
return JniHelper::callStaticStringMethod(Cocos2dxHelperClassName, "getCurrentLanguage");
}
bool openURLJNI(const std::string& url)
{
return JniHelper::callStaticBooleanMethod(Cocos2dxHelperClassName, "openURL", url);
}
void setAnimationIntervalJNI(float interval)
{
JniHelper::callStaticVoidMethod(Cocos2dxRendererClassName, "setAnimationInterval", interval);
}
@@ -1,5 +1,5 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
@@ -22,25 +22,23 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include "platform/android/jni/JniHelper.h"
#include <jni.h>
#include "base/CCEventAcceleration.h"
#include <string>
#define TG3_GRAVITY_EARTH (9.80665f)
typedef void (*EditTextCallback)(const std::string& text, void* ctx);
using namespace cocos2d;
extern std::string getApkPathJNI();
extern std::string getPackageNameJNI();
extern int getObbAssetFileDescriptorJNI(const std::string& path, long* startOffset, long* size);
extern void convertEncodingJNI(const std::string& src, int byteSize, const std::string& fromCharset, std::string& dst, const std::string& newCharset);
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxAccelerometer_onSensorChanged(JNIEnv* env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp) {
// Acceleration a;
// a.x = -((double)x / TG3_GRAVITY_EARTH);
// a.y = -((double)y / TG3_GRAVITY_EARTH);
// a.z = -((double)z / TG3_GRAVITY_EARTH);
// a.timestamp = (double)timeStamp;
extern int getDeviceSampleRateJNI();
extern int getDeviceAudioBufferSizeInFramesJNI();
// EventAcceleration* event = new (std::nothrow) EventAcceleration(a);
// Director::getInstance()->getEventDispatcher()->dispatchEvent(event);
// event->release();
}
}
extern int getFontSizeAccordingHeightJNI(int height);
extern std::string getStringWithEllipsisJNI(const std::string& text, float width, float fontSize);
extern std::string getCurrentLanguageJNI();
extern bool openURLJNI(const std::string& url);
extern void setAnimationIntervalJNI(float interval);
@@ -1,118 +0,0 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "base/CCEventKeyboard.h"
#include <android/log.h>
#include <jni.h>
#include <unordered_map>
using namespace cocos2d;
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesBegin(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) {
intptr_t idlong = id;
// cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, &idlong, &x, &y);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesEnd(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) {
intptr_t idlong = id;
// cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, &idlong, &x, &y);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesMove(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) {
int size = env->GetArrayLength(ids);
jint id[size];
jfloat x[size];
jfloat y[size];
env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, x);
env->GetFloatArrayRegion(ys, 0, size, y);
intptr_t idlong[size];
for(int i = 0; i < size; i++)
idlong[i] = id[i];
// cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(size, idlong, x, y);
}
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesCancel(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) {
int size = env->GetArrayLength(ids);
jint id[size];
jfloat x[size];
jfloat y[size];
env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, x);
env->GetFloatArrayRegion(ys, 0, size, y);
intptr_t idlong[size];
for(int i = 0; i < size; i++)
idlong[i] = id[i];
// cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(size, idlong, x, y);
}
#define KEYCODE_BACK 0x04
#define KEYCODE_MENU 0x52
#define KEYCODE_DPAD_UP 0x13
#define KEYCODE_DPAD_DOWN 0x14
#define KEYCODE_DPAD_LEFT 0x15
#define KEYCODE_DPAD_RIGHT 0x16
#define KEYCODE_ENTER 0x42
#define KEYCODE_PLAY 0x7e
#define KEYCODE_DPAD_CENTER 0x17
static std::unordered_map<int, cocos2d::EventKeyboard::KeyCode> g_keyCodeMap = {
{ KEYCODE_BACK , cocos2d::EventKeyboard::KeyCode::KEY_ESCAPE},
{ KEYCODE_MENU , cocos2d::EventKeyboard::KeyCode::KEY_MENU},
{ KEYCODE_DPAD_UP , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_UP },
{ KEYCODE_DPAD_DOWN , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_DOWN },
{ KEYCODE_DPAD_LEFT , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_LEFT },
{ KEYCODE_DPAD_RIGHT , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_RIGHT },
{ KEYCODE_ENTER , cocos2d::EventKeyboard::KeyCode::KEY_ENTER},
{ KEYCODE_PLAY , cocos2d::EventKeyboard::KeyCode::KEY_PLAY},
{ KEYCODE_DPAD_CENTER , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_CENTER},
};
JNIEXPORT jboolean JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeKeyEvent(JNIEnv * env, jobject thiz, jint keyCode, jboolean isPressed) {
// Director* pDirector = Director::getInstance();
// auto iterKeyCode = g_keyCodeMap.find(keyCode);
// if (iterKeyCode == g_keyCodeMap.end()) {
// return JNI_FALSE;
// }
// cocos2d::EventKeyboard::KeyCode cocos2dKey = g_keyCodeMap.at(keyCode);
// cocos2d::EventKeyboard* event = new (std::nothrow) cocos2d::EventKeyboard(cocos2dKey, isPressed);
// cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(event);
// event->release();
return JNI_TRUE;
}}
@@ -1,7 +0,0 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
@@ -1,7 +0,0 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.cocos2dx.lib">
<application android:allowBackup="true">
</application>
</manifest>
@@ -1,30 +0,0 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
sourceSets.main {
aidl.srcDir "../java/src"
java.srcDirs = ['../java/src','../ControllerManualAdapter/src']
manifest.srcFile "AndroidManifest.xml"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: '../ControllerManualAdapter/libs', include: ['*.jar'])
}
@@ -1,17 +0,0 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in E:\developSoftware\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 *;
#}
@@ -40,6 +40,7 @@ void EventDispatcher::dispatchKeyEvent(int key, int action)
void EventDispatcher::dispatchTickEvent()
{
se::AutoHandleScope scope;
auto se = se::ScriptEngine::getInstance();
static se::Value tickVal;
static std::chrono::steady_clock::time_point prevTime;
@@ -1,140 +0,0 @@
LOCAL_PATH := $(call my-dir)
#==============================================================
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2d_js_static
LOCAL_MODULE_FILENAME := libjscocos2d
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := ../auto/jsb_gfx_auto.cpp \
../manual/jsb_classtype.cpp \
../manual/jsb_conversions.cpp \
../manual/jsb_gfx_manual.cpp \
../manual/jsb_global.cpp \
../manual/jsb_renderer_manual.cpp \
../auto/jsb_renderer_auto.cpp \
../jswrapper/config.cpp \
../jswrapper/HandleObject.cpp \
../jswrapper/MappingUtils.cpp \
../jswrapper/RefCounter.cpp \
../jswrapper/Value.cpp \
../jswrapper/State.cpp \
../jswrapper/v8/Class.cpp \
../jswrapper/v8/Object.cpp \
../jswrapper/v8/ObjectWrap.cpp \
../jswrapper/v8/SHA1.cpp \
../jswrapper/v8/ScriptEngine.cpp \
../jswrapper/v8/Utils.cpp \
../jswrapper/v8/env.cc \
../jswrapper/v8/inspector_agent.cc \
../jswrapper/v8/inspector_io.cc \
../jswrapper/v8/inspector_socket.cc \
../jswrapper/v8/inspector_socket_server.cc \
../jswrapper/v8/node.cc \
../jswrapper/v8/node_debug_options.cc \
../jswrapper/v8/util.cc \
../jswrapper/v8/http_parser.c \
../jswrapper/v8/SHA1.cpp
# LOCAL_SRC_FILES := \
# ../jswrapper/RefCounter.cpp \
# ../jswrapper/State.cpp \
# ../jswrapper/Value.cpp \
# ../jswrapper/HandleObject.cpp \
# ../jswrapper/MappingUtils.cpp \
# ../jswrapper/sm/Class.cpp \
# ../jswrapper/sm/ScriptEngine.cpp \
# ../jswrapper/sm/Object.cpp \
# ../jswrapper/sm/Utils.cpp \
# ../jswrapper/v8/Class.cpp \
# ../jswrapper/v8/Object.cpp \
# ../jswrapper/v8/ObjectWrap.cpp \
# ../jswrapper/v8/ScriptEngine.cpp \
# ../jswrapper/v8/Utils.cpp \
# ../jswrapper/v8/env.cc \
# ../jswrapper/v8/inspector_agent.cc \
# ../jswrapper/v8/inspector_io.cc \
# ../jswrapper/v8/inspector_socket.cc \
# ../jswrapper/v8/inspector_socket_server.cc \
# ../jswrapper/v8/node.cc \
# ../jswrapper/v8/node_debug_options.cc \
# ../jswrapper/v8/util.cc \
# ../jswrapper/v8/http_parser.c \
# ../jswrapper/v8/SHA1.cpp \
# ../auto/jsb_box2d_auto.cpp \
# ../auto/jsb_cocos2dx_audioengine_auto.cpp \
# ../auto/jsb_cocos2dx_auto.cpp \
# ../auto/jsb_cocos2dx_dragonbones_auto.cpp \
# ../auto/jsb_cocos2dx_experimental_video_auto.cpp \
# ../auto/jsb_cocos2dx_experimental_webView_auto.cpp \
# ../auto/jsb_cocos2dx_extension_auto.cpp \
# ../auto/jsb_cocos2dx_network_auto.cpp \
# ../auto/jsb_cocos2dx_spine_auto.cpp \
# ../auto/jsb_cocos2dx_ui_auto.cpp \
# ../auto/jsb_creator_auto.cpp \
# ../auto/jsb_creator_camera_auto.cpp \
# ../auto/jsb_creator_graphics_auto.cpp \
# ../auto/jsb_creator_physics_auto.cpp \
# ../manual/BaseJSAction.cpp \
# ../manual/JavaScriptJavaBridge.cpp \
# ../manual/ScriptingCore.cpp \
# ../manual/jsb_helper.cpp \
# ../manual/jsb_box2d_manual.cpp \
# ../manual/jsb_classtype.cpp \
# ../manual/jsb_cocos2dx_extension_manual.cpp \
# ../manual/jsb_cocos2dx_manual.cpp \
# ../manual/jsb_conversions.cpp \
# ../manual/jsb_creator_manual.cpp \
# ../manual/jsb_creator_physics_manual.cpp \
# ../manual/jsb_dragonbones_manual.cpp \
# ../manual/jsb_global.cpp \
# ../manual/jsb_node.cpp \
# ../manual/jsb_opengl_functions.cpp \
# ../manual/jsb_opengl_manual.cpp \
# ../manual/jsb_opengl_node.cpp \
# ../manual/jsb_opengl_registration.cpp \
# ../manual/jsb_socketio.cpp \
# ../manual/jsb_spine_manual.cpp \
# ../manual/jsb_websocket.cpp \
# ../manual/jsb_xmlhttprequest.cpp
LOCAL_CFLAGS := -DHAVE_INSPECTOR
LOCAL_EXPORT_CFLAGS :=
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../manual \
$(LOCAL_PATH)/../manual/cocostudio \
$(LOCAL_PATH)/../manual/spine \
$(LOCAL_PATH)/../manual/platform/android \
$(LOCAL_PATH)/../auto \
$(LOCAL_PATH)/../../../2d \
$(LOCAL_PATH)/../../../base \
$(LOCAL_PATH)/../../../ui \
$(LOCAL_PATH)/../../../audio/include \
$(LOCAL_PATH)/../../../storage \
$(LOCAL_PATH)/../../../../extensions \
$(LOCAL_PATH)/../../../editor-support/spine \
$(LOCAL_PATH)/../../../editor-support/cocosbuilder \
$(LOCAL_PATH)/../../../editor-support/cocostudio \
$(LOCAL_PATH)/../../../editor-support/creator \
$(LOCAL_PATH)/../../../renderer \
$(LOCAL_PATH)/../../../renderer/gfx
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../manual \
$(LOCAL_PATH)/../auto \
$(LOCAL_PATH)/../../../audio/include
LOCAL_EXPORT_LDLIBS := -lz
LOCAL_STATIC_LIBRARIES := cocos2dx_static
# LOCAL_STATIC_LIBRARIES += spidermonkey_static
LOCAL_STATIC_LIBRARIES += uv_static
LOCAL_STATIC_LIBRARIES += v8_static
include $(BUILD_STATIC_LIBRARY)
#==============================================================
$(call import-module,cocos)
@@ -3,12 +3,12 @@ import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '26.0.2'
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
buildToolsVersion '27.0.1'
defaultConfig {
applicationId "org.cocos2dx.hellojavascript"
minSdkVersion 10
minSdkVersion PROP_MIN_SDK_VERSION
targetSdkVersion PROP_TARGET_SDK_VERSION
versionCode 1
versionName "1.0"
@@ -19,7 +19,7 @@ android {
// skip the NDK Build step if PROP_NDK_MODE is none
targets 'cocos2djs'
arguments 'NDK_TOOLCHAIN_VERSION=4.9'
arguments 'APP_PLATFORM=android-'+PROP_TARGET_SDK_VERSION
arguments 'APP_PLATFORM=android-'+PROP_MIN_SDK_VERSION
def module_paths = [project.file("${COCOS_X_ROOT}"),
project.file("${COCOS_X_ROOT}/cocos"),
@@ -28,11 +28,11 @@ LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic
endif
LOCAL_STATIC_LIBRARIES := cocos2d_js_static
LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_EXPORT_CFLAGS := -DCOCOS2D_DEBUG=2 -DCOCOS2D_JAVASCRIPT
include $(BUILD_SHARED_LIBRARY)
$(call import-module, scripting/js-bindings/proj.android)
$(call import-module, .)
@@ -17,7 +17,9 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
PROP_TARGET_SDK_VERSION=22
PROP_MIN_SDK_VERSION=14
PROP_COMPILE_SDK_VERSION=22
PROP_TARGET_SDK_VERSION=27
PROP_APP_ABI=armeabi-v7a
RELEASE_STORE_FILE=