Skip to content

Commit

Permalink
Improve GPU rendering and fix some bugs
Browse files Browse the repository at this point in the history
Add license file.
Add android project file.
Using source image opaque info for better occlusion culling in both CPU and GPU drawing route.
Fix infinity issue in ThreadImpl.
Fix audio volume issue in KRMoviePlayer.
Some modify for clang compiler compatible.
Some modify in tjs2 code for multi-thread compatible.
  • Loading branch information
ZeaS committed Jan 17, 2017
1 parent 0b8a337 commit b2efd9c
Show file tree
Hide file tree
Showing 96 changed files with 3,855 additions and 1,559 deletions.
892 changes: 892 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions project/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Replace org.libsdl.app with the identifier of your game below, e.g.
com.gamemaker.game
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.tvp.kirikiri2"
android:versionCode="58"
android:versionName="1.3.0"
android:installLocation="auto">

<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="9"/>

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />

<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<supports-screens android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowBackup="true">
<activity android:name="Kirikiroid2"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
43 changes: 43 additions & 0 deletions project/android/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ndk-build MODULE_PATH=jni

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := kirikiri2

LOCAL_MODULE_FILENAME := libgame

LOCAL_SRC_FILES := src/SDL_android_main.cpp

LOCAL_LDLIBS := -lGLESv1_CM -llog -ldl -lGLESv2 -landroid -lm
LOCAL_LDLIBS += -Wl,--wrap=malloc -Wl,--wrap=free -Wl,--wrap=realloc -Wl,--wrap=calloc

LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../../vendor/libgdiplus/src \
$(LOCAL_PATH)/../../../vendor/google_breakpad/current/src \
$(LOCAL_PATH)/../../../vendor/google_breakpad/current/src/common/android/include \
$(LOCAL_PATH)/../../../src/core/environ \
$(LOCAL_PATH)/../../../src/core/environ/android \
$(LOCAL_PATH)/../../../src/core/tjs2 \
$(LOCAL_PATH)/../../../src/core/base \
$(LOCAL_PATH)/../../../src/core/visual \
$(LOCAL_PATH)/../../../src/core/visual/win32 \
$(LOCAL_PATH)/../../../src/core/sound \
$(LOCAL_PATH)/../../../src/core/sound/win32 \
$(LOCAL_PATH)/../../../src/core/utils \

LOCAL_WHOLE_STATIC_LIBRARIES := kr2plugin krkr2 krkr2_neon_opt cocos2dx_static
#LOCAL_WHOLE_STATIC_LIBRARIES += tcmalloc
LOCAL_STATIC_LIBRARIES := android-ndk-profiler
LOCAL_CPPFLAGS += -Dtypeof=decltype

include $(BUILD_SHARED_LIBRARY)
$(call import-module, core)
$(call import-module, ARM_neon)
$(call import-module, plugins)
#$(call import-module, png) #cocos
#$(call import-module, jpeg) #cocos
$(call import-module, cocos)
#$(call import-module, tcmalloc)
#$(call import-module, ../../../vendor/libgdiplus/jni)
9 changes: 9 additions & 0 deletions project/android/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -std=c++11
APP_CPPFLAGS += -O3 -DNDEBUG -Wno-inconsistent-missing-override
#APP_CPPFLAGS += -D__DO_PROF__ -g -pg
APP_ABI := armeabi-v7a
#APP_ABI += arm64-v8a
APP_PLATFORM := android-9
#NDK_TOOLCHAIN_VERSION := 4.9
NDK_TOOLCHAIN_VERSION := clang
277 changes: 277 additions & 0 deletions project/android/jni/src/SDL_android_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
/* Include the SDL main definition header */
#include <jni.h>
#include "platform/android/jni/JniHelper.h"
#include "cocos2d/AppDelegate.h"
#include "cocos2d/MainScene.h"
#include "ConfigManager/GlobalConfigManager.h"

/*******************************************************************************
Functions called by JNI
*******************************************************************************/
#include <string.h>
#include <string>
#include <condition_variable>
#include <mutex>
#include "client/linux/handler/exception_handler.h"
#include "client/linux/handler/minidump_descriptor.h"

//std::string Android_GetDumpStoragePath();
void start_profile() {}
void stop_profile() {}

static bool __DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
void* context, bool succeeded)
{
return succeeded;
}

extern bool TVPSystemUninitCalled;

static bool __DumpFilter(void *data) {
if(TVPSystemUninitCalled) return false; // if trying exit system, ignore all exception
return true;
}


//static void __InitAndroidDump() {
// static google_breakpad::MinidumpDescriptor descriptor(Android_GetDumpStoragePath());
// static google_breakpad::ExceptionHandler eh(descriptor, __DumpFilter, __DumpCallback,
// NULL, true, -1);
//}

void cocos_android_app_init (JNIEnv* env) { // for cocos3.10+
// __InitAndroidDump();
static TVPAppDelegate *pAppDelegate = new TVPAppDelegate();
}

void cocos_android_app_init(JNIEnv* env, jobject thiz) {
// __InitAndroidDump();
static TVPAppDelegate *pAppDelegate = new TVPAppDelegate();
}

namespace kr2android {
extern std::condition_variable MessageBoxCond;
extern std::mutex MessageBoxLock;
extern int MsgBoxRet;
extern std::string MessageBoxRetText;
}
void Android_PushEvents(const std::function<void()> &func);
using namespace kr2android;
extern "C" {
void Java_org_tvp_kirikiri2_KR2Activity_initDump(JNIEnv* env, jclass cls, jstring path) {
const char* pszPath = env->GetStringUTFChars(path, NULL);
if (pszPath && *pszPath) {
static google_breakpad::MinidumpDescriptor descriptor(pszPath);
static google_breakpad::ExceptionHandler eh(descriptor, __DumpFilter, __DumpCallback,
NULL, true, -1);
}
env->ReleaseStringUTFChars(path, pszPath);
}

void Java_org_tvp_kirikiri2_KR2Activity_onMessageBoxOK(JNIEnv* env, jclass cls, jint nButton) {
MsgBoxRet = nButton;
MessageBoxCond.notify_one();
}

void Java_org_tvp_kirikiri2_KR2Activity_onMessageBoxText(JNIEnv* env, jclass cls, jstring text) {
const char* pszText = env->GetStringUTFChars(text, NULL);
if (pszText && *pszText) {
MessageBoxRetText = pszText;
}
env->ReleaseStringUTFChars(text, pszText);
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeTouchesBegin(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) {
intptr_t idlong = id;
Android_PushEvents([idlong, x, y](){
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesBegin(1, (intptr_t*)&idlong, (float*)&x, (float*)&y);
});
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeTouchesEnd(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) {
intptr_t idlong = id;
Android_PushEvents([idlong, x, y](){
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesEnd(1, (intptr_t*)&idlong, (float*)&x, (float*)&y);
});
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeTouchesMove(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) {
int size = env->GetArrayLength(ids);
if (size == 1) {
intptr_t idlong;
jint id;
jfloat x;
jfloat y;
env->GetIntArrayRegion(ids, 0, size, &id);
env->GetFloatArrayRegion(xs, 0, size, &x);
env->GetFloatArrayRegion(ys, 0, size, &y);
idlong = id;
Android_PushEvents([idlong, x, y](){
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(1, (intptr_t*)&idlong, (float*)&x, (float*)&y);
});
return;
}

jint id[size];
std::vector<jfloat> x; x.resize(size);
std::vector<jfloat> y; y.resize(size);

env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, &x[0]);
env->GetFloatArrayRegion(ys, 0, size, &y[0]);

std::vector<intptr_t> idlong; idlong.resize(size);
for (int i = 0; i < size; i++)
idlong[i] = id[i];

Android_PushEvents([idlong, x, y](){
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesMove(idlong.size(), (intptr_t*)&idlong[0], (float*)&x[0], (float*)&y[0]);
});
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeTouchesCancel(JNIEnv * env, jobject thiz, jintArray ids, jfloatArray xs, jfloatArray ys) {
int size = env->GetArrayLength(ids);
if (size == 1) {
intptr_t idlong;
jint id;
jfloat x;
jfloat y;
env->GetIntArrayRegion(ids, 0, size, &id);
env->GetFloatArrayRegion(xs, 0, size, &x);
env->GetFloatArrayRegion(ys, 0, size, &y);
idlong = id;
Android_PushEvents([idlong, x, y](){
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(1, (intptr_t*)&idlong, (float*)&x, (float*)&y);
});
return;
}

jint id[size];
std::vector<jfloat> x; x.resize(size);
std::vector<jfloat> y; y.resize(size);

env->GetIntArrayRegion(ids, 0, size, id);
env->GetFloatArrayRegion(xs, 0, size, &x[0]);
env->GetFloatArrayRegion(ys, 0, size, &y[0]);

std::vector<intptr_t> idlong; idlong.resize(size);
for (int i = 0; i < size; i++)
idlong[i] = id[i];

Android_PushEvents([idlong, x, y](){
cocos2d::Director::getInstance()->getOpenGLView()->handleTouchesCancel(idlong.size(), (intptr_t*)&idlong[0], (float*)&x[0], (float*)&y[0]);
});
}

#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
#define KEYCODE_DEL 0x43

JNIEXPORT jboolean JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeKeyAction(JNIEnv * env, jclass cls, jint keyCode, jboolean isPress) {
cocos2d::EventKeyboard::KeyCode pKeyCode;
switch (keyCode) {
case KEYCODE_BACK : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_ESCAPE ; break;
case KEYCODE_MENU : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_MENU ; break;
case KEYCODE_DPAD_UP : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_DPAD_UP ; break;
case KEYCODE_DPAD_DOWN : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_DPAD_DOWN ; break;
case KEYCODE_DPAD_LEFT : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_DPAD_LEFT ; break;
case KEYCODE_DPAD_RIGHT : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_DPAD_RIGHT; break;
case KEYCODE_ENTER : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_ENTER ; break;
case KEYCODE_PLAY : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_PLAY ; break;
case KEYCODE_DPAD_CENTER: pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_DPAD_CENTER; break;
case KEYCODE_DEL : pKeyCode = cocos2d::EventKeyboard::KeyCode::KEY_BACKSPACE; break;
default: return JNI_FALSE;
}

Android_PushEvents([pKeyCode, isPress](){
cocos2d::EventKeyboard event(pKeyCode, isPress);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
});
return JNI_TRUE;
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeInsertText(JNIEnv* env, jclass cls, jstring text) {
const char* pszText = env->GetStringUTFChars(text, NULL);
if (pszText && *pszText) {
std::string str = pszText;
Android_PushEvents([str](){
cocos2d::IMEDispatcher::sharedDispatcher()->dispatchInsertText(str.c_str(), str.length());
});
}
env->ReleaseStringUTFChars(text, pszText);
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeDeleteBackward(JNIEnv* env, jclass cls) {
Android_PushEvents(std::bind(&cocos2d::IMEDispatcher::dispatchDeleteBackward,
cocos2d::IMEDispatcher::sharedDispatcher()));
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeCharInput(JNIEnv* env, jclass cls, jint keyCode) {
TVPMainScene *pScene = TVPMainScene::GetInstance();
if (!pScene) return;
pScene->getScheduler()->performFunctionInCocosThread(std::bind(&TVPMainScene::onCharInput, keyCode));
}

JNIEXPORT void JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeCommitText(
JNIEnv* env, jclass cls,
jstring text, jint newCursorPosition)
{
TVPMainScene *pScene = TVPMainScene::GetInstance();
if (!pScene) return;
const char *utftext = env->GetStringUTFChars(text, NULL);
std::string str(utftext);
pScene->getScheduler()->performFunctionInCocosThread(std::bind(&TVPMainScene::onTextInput, str));
env->ReleaseStringUTFChars(text, utftext);
}

JNIEXPORT jboolean JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeGetHideSystemButton(JNIEnv* env, jclass cls)
{
return GlobalConfigManager::GetInstance()->GetValue<bool>("hide_android_sys_btn", false);
}

static float _mouseX, _mouseY;

JNIEXPORT jboolean JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeHoverMoved(JNIEnv* env, jclass cls, jfloat x, jfloat y)
{
Android_PushEvents([x, y]() {
cocos2d::GLView *glview = cocos2d::Director::getInstance()->getOpenGLView();
float _scaleX = glview->getScaleX(), _scaleY = glview->getScaleY();
_mouseX = x; _mouseY = y;
const cocos2d::Rect _viewPortRect = glview->getViewPortRect();

float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;

cocos2d::EventMouse event(cocos2d::EventMouse::MouseEventType::MOUSE_MOVE);
event.setCursorPosition(cursorX, cursorY);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
});
return true;
}

JNIEXPORT jboolean JNICALL Java_org_tvp_kirikiri2_KR2Activity_nativeMouseScrolled(JNIEnv* env, jclass cls, jfloat v)
{
Android_PushEvents([v]() {
cocos2d::GLView *glview = cocos2d::Director::getInstance()->getOpenGLView();
float _scaleX = glview->getScaleX(), _scaleY = glview->getScaleY();
const cocos2d::Rect _viewPortRect = glview->getViewPortRect();

float cursorX = (_mouseX - _viewPortRect.origin.x) / _scaleX;
float cursorY = (_viewPortRect.origin.y + _viewPortRect.size.height - _mouseY) / _scaleY;

cocos2d::EventMouse event(cocos2d::EventMouse::MouseEventType::MOUSE_SCROLL);
event.setScrollData(0, v);
event.setCursorPosition(cursorX, cursorY);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
});
return true;
}

}
15 changes: 15 additions & 0 deletions project/android/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-22
android.library.reference.1=../../vendor/cocos2d-x/current/cocos/platform/android/java
Loading

0 comments on commit b2efd9c

Please sign in to comment.