移除android的加载流程
This commit is contained in:
parent
eb5c0886bd
commit
ab934e73ca
@ -89,16 +89,16 @@ std::shared_ptr<Scheduler> Application::_scheduler = nullptr;
|
||||
Application::Application(const std::string& name, int width, int height)
|
||||
{
|
||||
Application::_instance = this;
|
||||
Configuration::getInstance();
|
||||
// Configuration::getInstance();
|
||||
|
||||
_scheduler = std::make_shared<Scheduler>();
|
||||
|
||||
PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
|
||||
PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
|
||||
PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
|
||||
// PFNGLGENVERTEXARRAYSOESPROC glGenVertexArraysOESEXT = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
|
||||
// PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
|
||||
// PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArraysOES");
|
||||
|
||||
_renderTexture = new RenderTexture(width, height);
|
||||
updateViewSize(width, height);
|
||||
// _renderTexture = new RenderTexture(width, height);
|
||||
// updateViewSize(width, height);
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
|
@ -37,7 +37,6 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.AssetManager;
|
||||
import android.media.AudioManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
@ -54,11 +53,9 @@ import android.view.Surface;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.vending.expansion.zipfile.APKExpansionSupport;
|
||||
import com.android.vending.expansion.zipfile.ZipResourceFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -175,35 +172,35 @@ public class Cocos2dxHelper {
|
||||
if (!sInited) {
|
||||
|
||||
PackageManager pm = activity.getPackageManager();
|
||||
boolean isSupportLowLatency = pm.hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY);
|
||||
// boolean isSupportLowLatency = pm.hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY);
|
||||
|
||||
Log.d(TAG, "isSupportLowLatency:" + isSupportLowLatency);
|
||||
// Log.d(TAG, "isSupportLowLatency:" + isSupportLowLatency);
|
||||
|
||||
int sampleRate = 44100;
|
||||
int bufferSizeInFrames = 192;
|
||||
// int sampleRate = 44100;
|
||||
// int bufferSizeInFrames = 192;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
AudioManager am = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
|
||||
// use reflection to remove dependence of API 17 when compiling
|
||||
// if (Build.VERSION.SDK_INT >= 17) {
|
||||
// AudioManager am = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
|
||||
// // use reflection to remove dependence of API 17 when compiling
|
||||
//
|
||||
// // AudioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
|
||||
// final Class audioManagerClass = AudioManager.class;
|
||||
// Object[] parameters = new Object[]{Cocos2dxReflectionHelper.<String>getConstantValue(audioManagerClass, "PROPERTY_OUTPUT_SAMPLE_RATE")};
|
||||
// final String strSampleRate = Cocos2dxReflectionHelper.<String>invokeInstanceMethod(am, "getProperty", new Class[]{String.class}, parameters);
|
||||
//
|
||||
// // AudioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
|
||||
// parameters = new Object[]{Cocos2dxReflectionHelper.<String>getConstantValue(audioManagerClass, "PROPERTY_OUTPUT_FRAMES_PER_BUFFER")};
|
||||
// final String strBufferSizeInFrames = Cocos2dxReflectionHelper.<String>invokeInstanceMethod(am, "getProperty", new Class[]{String.class}, parameters);
|
||||
//
|
||||
// sampleRate = Integer.parseInt(strSampleRate);
|
||||
// bufferSizeInFrames = Integer.parseInt(strBufferSizeInFrames);
|
||||
//
|
||||
// Log.d(TAG, "sampleRate: " + sampleRate + ", framesPerBuffer: " + bufferSizeInFrames);
|
||||
// } else {
|
||||
// Log.d(TAG, "android version is lower than 17");
|
||||
// }
|
||||
|
||||
// AudioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
|
||||
final Class audioManagerClass = AudioManager.class;
|
||||
Object[] parameters = new Object[]{Cocos2dxReflectionHelper.<String>getConstantValue(audioManagerClass, "PROPERTY_OUTPUT_SAMPLE_RATE")};
|
||||
final String strSampleRate = Cocos2dxReflectionHelper.<String>invokeInstanceMethod(am, "getProperty", new Class[]{String.class}, parameters);
|
||||
|
||||
// AudioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
|
||||
parameters = new Object[]{Cocos2dxReflectionHelper.<String>getConstantValue(audioManagerClass, "PROPERTY_OUTPUT_FRAMES_PER_BUFFER")};
|
||||
final String strBufferSizeInFrames = Cocos2dxReflectionHelper.<String>invokeInstanceMethod(am, "getProperty", new Class[]{String.class}, parameters);
|
||||
|
||||
sampleRate = Integer.parseInt(strSampleRate);
|
||||
bufferSizeInFrames = Integer.parseInt(strBufferSizeInFrames);
|
||||
|
||||
Log.d(TAG, "sampleRate: " + sampleRate + ", framesPerBuffer: " + bufferSizeInFrames);
|
||||
} else {
|
||||
Log.d(TAG, "android version is lower than 17");
|
||||
}
|
||||
|
||||
nativeSetAudioDeviceInfo(isSupportLowLatency, sampleRate, bufferSizeInFrames);
|
||||
// nativeSetAudioDeviceInfo(isSupportLowLatency, sampleRate, bufferSizeInFrames);
|
||||
|
||||
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
||||
|
||||
@ -212,10 +209,10 @@ public class Cocos2dxHelper {
|
||||
|
||||
Cocos2dxHelper.nativeSetApkPath(Cocos2dxHelper.getAssetsPath());
|
||||
|
||||
Cocos2dxHelper.sCocos2dxAccelerometer = new Cocos2dxAccelerometer(activity);
|
||||
// Cocos2dxHelper.sCocos2dxAccelerometer = new Cocos2dxAccelerometer(activity);
|
||||
Cocos2dxHelper.sAssetManager = activity.getAssets();
|
||||
Cocos2dxHelper.nativeSetContext((Context)activity, Cocos2dxHelper.sAssetManager);
|
||||
Cocos2dxHelper.sVibrateService = (Vibrator)activity.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
// Cocos2dxHelper.sVibrateService = (Vibrator)activity.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
sInited = true;
|
||||
|
||||
@ -338,31 +335,31 @@ public class Cocos2dxHelper {
|
||||
}
|
||||
|
||||
public static void vibrate(float duration) {
|
||||
try {
|
||||
if (sVibrateService != null && sVibrateService.hasVibrator()) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 26) {
|
||||
Class<?> vibrationEffectClass = Class.forName("android.os.VibrationEffect");
|
||||
if(vibrationEffectClass != null) {
|
||||
final int DEFAULT_AMPLITUDE = Cocos2dxReflectionHelper.<Integer>getConstantValue(vibrationEffectClass,
|
||||
"DEFAULT_AMPLITUDE");
|
||||
//VibrationEffect.createOneShot(long milliseconds, int amplitude)
|
||||
final Method method = vibrationEffectClass.getMethod("createOneShot",
|
||||
new Class[]{Long.TYPE, Integer.TYPE});
|
||||
Class<?> type = method.getReturnType();
|
||||
|
||||
Object effect = method.invoke(vibrationEffectClass,
|
||||
new Object[]{(long) (duration * 1000), DEFAULT_AMPLITUDE});
|
||||
//sVibrateService.vibrate(VibrationEffect effect);
|
||||
Cocos2dxReflectionHelper.invokeInstanceMethod(sVibrateService,"vibrate",
|
||||
new Class[]{type}, new Object[]{(effect)});
|
||||
}
|
||||
} else {
|
||||
sVibrateService.vibrate((long) (duration * 1000));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// try {
|
||||
// if (sVibrateService != null && sVibrateService.hasVibrator()) {
|
||||
// if (android.os.Build.VERSION.SDK_INT >= 26) {
|
||||
// Class<?> vibrationEffectClass = Class.forName("android.os.VibrationEffect");
|
||||
// if(vibrationEffectClass != null) {
|
||||
// final int DEFAULT_AMPLITUDE = Cocos2dxReflectionHelper.<Integer>getConstantValue(vibrationEffectClass,
|
||||
// "DEFAULT_AMPLITUDE");
|
||||
// //VibrationEffect.createOneShot(long milliseconds, int amplitude)
|
||||
// final Method method = vibrationEffectClass.getMethod("createOneShot",
|
||||
// new Class[]{Long.TYPE, Integer.TYPE});
|
||||
// Class<?> type = method.getReturnType();
|
||||
//
|
||||
// Object effect = method.invoke(vibrationEffectClass,
|
||||
// new Object[]{(long) (duration * 1000), DEFAULT_AMPLITUDE});
|
||||
// //sVibrateService.vibrate(VibrationEffect effect);
|
||||
// Cocos2dxReflectionHelper.invokeInstanceMethod(sVibrateService,"vibrate",
|
||||
// new Class[]{type}, new Object[]{(effect)});
|
||||
// }
|
||||
// } else {
|
||||
// sVibrateService.vibrate((long) (duration * 1000));
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
|
@ -45,6 +45,11 @@
|
||||
#endif
|
||||
#define JNI_RENDER(FUNC) JNI_METHOD1(ORG_RENDER_CLASS_NAME,FUNC)
|
||||
|
||||
#ifndef ORG_JS_HELPER_CLASS_NAME
|
||||
#define ORG_JS_HELPER_CLASS_NAME org_cocos2dx_lib_CocosJSHelper
|
||||
#endif
|
||||
#define JNI_JS_HELPER(FUNC) JNI_METHOD1(ORG_JS_HELPER_CLASS_NAME,FUNC)
|
||||
|
||||
|
||||
#ifndef ORG_ACTIVITY_CLASS_NAME
|
||||
#define ORG_ACTIVITY_CLASS_NAME org_cocos2dx_lib_Cocos2dxActivity
|
||||
@ -159,7 +164,7 @@ extern "C"
|
||||
* Cocos2dxActivity native functions implementation.
|
||||
*****************************************************/
|
||||
|
||||
JNIEXPORT jintArray JNICALL JNI_ACTIVITY(getGLContextAttrs)(JNIEnv* env, jobject thiz)
|
||||
JNIEXPORT jintArray JNICALL JNI_ACTIVITY(getGLContextAttrs)(JNIEnv* env, jclass thiz)
|
||||
{
|
||||
//REFINE
|
||||
int tmp[7] = {8, 8, 8,
|
||||
@ -174,7 +179,7 @@ extern "C"
|
||||
* Cocos2dxRenderer native functions implementation.
|
||||
*****************************************************/
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeInit)(JNIEnv* env, jobject thiz, jint w, jint h, jstring jDefaultResourcePath)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeInit)(JNIEnv* env, jclass thiz, jint w, jint h, jstring jDefaultResourcePath)
|
||||
{
|
||||
g_width = w;
|
||||
g_height = h;
|
||||
@ -298,12 +303,12 @@ extern "C"
|
||||
g_app->onResume();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeInsertText)(JNIEnv* env, jobject thiz, jstring text)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeInsertText)(JNIEnv* env, jclass thiz, jstring text)
|
||||
{
|
||||
//REFINE
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeDeleteBackward)(JNIEnv* env, jobject thiz)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeDeleteBackward)(JNIEnv* env, jclass thiz)
|
||||
{
|
||||
//REFINE
|
||||
}
|
||||
@ -313,7 +318,7 @@ extern "C"
|
||||
//REFINE
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeOnSurfaceChanged)(JNIEnv* env, jobject thiz, jint w, jint h)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeOnSurfaceChanged)(JNIEnv* env, jclass thiz, jint w, jint h)
|
||||
{
|
||||
//REFINE
|
||||
}
|
||||
@ -322,7 +327,7 @@ extern "C"
|
||||
* Cocos2dxAccelerometer native functions implementation.
|
||||
***********************************************************/
|
||||
|
||||
JNIEXPORT void JNICALL JNI_ACCELEROMETER(onSensorChanged)(JNIEnv* env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp)
|
||||
JNIEXPORT void JNICALL JNI_ACCELEROMETER(onSensorChanged)(JNIEnv* env, jclass thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp)
|
||||
{
|
||||
//REFINE
|
||||
}
|
||||
@ -379,7 +384,7 @@ extern "C"
|
||||
cocos2d::EventDispatcher::dispatchTouchEvent(touchEvent);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesBegin)(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesBegin)(JNIEnv * env, jclass thiz, jint id, jfloat x, jfloat y)
|
||||
{
|
||||
if (g_isGameFinished) {
|
||||
return;
|
||||
@ -387,7 +392,7 @@ extern "C"
|
||||
dispatchTouchEventWithOnePoint(env, cocos2d::TouchEvent::Type::BEGAN, id, x, y);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesEnd)(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesEnd)(JNIEnv * env, jclass thiz, jint id, jfloat x, jfloat y)
|
||||
{
|
||||
if (g_isGameFinished) {
|
||||
return;
|
||||
@ -395,7 +400,7 @@ extern "C"
|
||||
dispatchTouchEventWithOnePoint(env, cocos2d::TouchEvent::Type::ENDED, id, x, y);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesMove)(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesMove)(JNIEnv * env, jclass thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
{
|
||||
if (g_isGameFinished) {
|
||||
return;
|
||||
@ -403,7 +408,7 @@ extern "C"
|
||||
dispatchTouchEventWithPoints(env, cocos2d::TouchEvent::Type::MOVED, ids, xs, ys);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesCancel)(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
JNIEXPORT void JNICALL JNI_RENDER(nativeTouchesCancel)(JNIEnv * env, jclass thiz, jintArray ids, jfloatArray xs, jfloatArray ys)
|
||||
{
|
||||
if (g_isGameFinished) {
|
||||
return;
|
||||
@ -411,7 +416,7 @@ extern "C"
|
||||
dispatchTouchEventWithPoints(env, cocos2d::TouchEvent::Type::CANCELLED, ids, xs, ys);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL JNI_RENDER(nativeKeyEvent)(JNIEnv * env, jobject thiz, jint keyCode, jboolean isPressed)
|
||||
JNIEXPORT jboolean JNICALL JNI_RENDER(nativeKeyEvent)(JNIEnv * env, jclass thiz, jint keyCode, jboolean isPressed)
|
||||
{
|
||||
if (g_isGameFinished) {
|
||||
return JNI_TRUE;
|
||||
@ -460,26 +465,26 @@ extern "C"
|
||||
* Cocos2dxHelper native functions implementation.
|
||||
***********************************************************/
|
||||
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetApkPath)(JNIEnv* env, jobject thiz, jstring apkPath)
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetApkPath)(JNIEnv* env, jclass thiz, jstring apkPath)
|
||||
{
|
||||
LOGD("nativeSetApkPath: %s", apkPath);
|
||||
g_apkPath = JniHelper::jstring2string(apkPath);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetContext)(JNIEnv* env, jobject thiz, jobject context, jobject assetManager)
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetContext)(JNIEnv* env, jclass thiz, jobject context, jobject assetManager)
|
||||
{
|
||||
JniHelper::setClassLoaderFrom(context);
|
||||
FileUtilsAndroid::setassetmanager(AAssetManager_fromJava(env, assetManager));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetAudioDeviceInfo)(JNIEnv* env, jobject thiz, jboolean isSupportLowLatency, jint deviceSampleRate, jint deviceAudioBufferSizeInFrames)
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetAudioDeviceInfo)(JNIEnv* env, jclass 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 JNI_HELPER(nativeSetEditTextDialogResult)(JNIEnv* env, jobject obj, jbyteArray text)
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetEditTextDialogResult)(JNIEnv* env, jclass obj, jbyteArray text)
|
||||
{
|
||||
jsize size = env->GetArrayLength(text);
|
||||
|
||||
@ -509,12 +514,15 @@ extern "C"
|
||||
* Cocos2dxAudioFocusManager native functions implementation.
|
||||
***********************************************************/
|
||||
|
||||
JNIEXPORT void JNICALL JNI_AUDIO(nativeOnAudioFocusChange)(JNIEnv* env, jobject thiz, jint focusChange)
|
||||
JNIEXPORT void JNICALL JNI_AUDIO(nativeOnAudioFocusChange)(JNIEnv* env, jclass thiz, jint focusChange)
|
||||
{
|
||||
// cocos_audioengine_focus_change(focusChange);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_CocosJSHelper_nativeJSInit(JNIEnv *env, jclass clazz, jstring resource_path) {
|
||||
/***********************************************************
|
||||
* CocosJSHelper native functions implementation.
|
||||
***********************************************************/
|
||||
JNIEXPORT void JNICALL JNI_JS_HELPER(nativeJSInit)(JNIEnv *env, jclass clazz, jstring resource_path) {
|
||||
g_app = cocos_android_app_init(env, 1, 1);
|
||||
se::ScriptEngine* se = se::ScriptEngine::getInstance();
|
||||
// se->addRegisterCallback(setCanvasCallback);
|
||||
|
@ -101,14 +101,6 @@ static cocos2d::network::Downloader *localDownloader()
|
||||
return g_localDownloader.get();
|
||||
}
|
||||
|
||||
static void localDownloaderCreateTask(const std::string &url, std::function<void(const std::string&, unsigned char*, int, const std::string&)> callback)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "jsb_loadimage_" << (g_localDownloaderTaskId++);
|
||||
std::string key = ss.str();
|
||||
auto task = localDownloader()->createDownloadDataTask(url, key);
|
||||
g_localDownloaderHandlers.emplace(std::make_pair(task->identifier, callback));
|
||||
}
|
||||
|
||||
static const char* BYTE_CODE_FILE_EXT = ".jsc";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user