mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
refactor android with new renderer (#1133)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user