diff --git a/spine-cocos2dx/example/proj.android/.classpath b/spine-cocos2dx/example/proj.android/.classpath new file mode 100644 index 000000000..3f9691c5d --- /dev/null +++ b/spine-cocos2dx/example/proj.android/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/spine-cocos2dx/example/proj.android/.cproject b/spine-cocos2dx/example/proj.android/.cproject new file mode 100644 index 000000000..1c04e397e --- /dev/null +++ b/spine-cocos2dx/example/proj.android/.cproject @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spine-cocos2dx/example/proj.android/.project b/spine-cocos2dx/example/proj.android/.project new file mode 100644 index 000000000..e7dc6bf2a --- /dev/null +++ b/spine-cocos2dx/example/proj.android/.project @@ -0,0 +1,131 @@ + + + SpineCocos2Dx + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?children? + ?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\|| + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + ${ProjDirPath}/build_native.sh + + + org.eclipse.cdt.make.core.buildCommand + bash + + + org.eclipse.cdt.make.core.buildLocation + ${ProjDirPath} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + false + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + Classes + 2 + COCOS2DX/projects/SpineCocos2Dx/Classes + + + cocos2dx + 2 + COCOS2DX/cocos2dx + + + extensions + 2 + COCOS2DX/extensions + + + scripting + 2 + COCOS2DX/scripting + + + diff --git a/spine-cocos2dx/example/proj.android/.settings/org.eclipse.jdt.core.prefs b/spine-cocos2dx/example/proj.android/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..8000cd6ca --- /dev/null +++ b/spine-cocos2dx/example/proj.android/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/spine-cocos2dx/example/proj.android/AndroidManifest.xml b/spine-cocos2dx/example/proj.android/AndroidManifest.xml new file mode 100644 index 000000000..f5ad3e1e1 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + diff --git a/spine-cocos2dx/example/proj.android/README.md b/spine-cocos2dx/example/proj.android/README.md new file mode 100644 index 000000000..c2bb3cc81 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/README.md @@ -0,0 +1,82 @@ +## Prerequisites: + +* Android NDK +* Android SDK **OR** Eclipse ADT Bundle +* Android AVD target installed + +## Building project + +There are two ways of building Android projects. + +1. Eclipse +2. Command Line + +### Import Project in Eclipse + +#### Features: + +1. Complete workflow from Eclipse, including: + a. Build C++. + b. Clean C++. + c. Build and Run whole project. + d. Logcat view. + e. Debug Java code. + f. Javascript editor. + g. Project management. +2. True C++ editing, including: + a. Code completion. + b. Jump to definition. + c. Refactoring tools etc. + d. Quick open C++ files. + + +#### Setup Eclipse Environment + + +**NOTE:** This step needs to be done only once to setup the Eclipse environment for cocos2d-x projects. Skip this section if you've done this before. + +1. Download Eclipse ADT bundle from [Google](http://developer.android.com/sdk/index.html) + + **OR** + + Install Eclipse with Java. Add ADT and CDT plugins. + +2. Set up Variables: + 1. Path Variable **COCOS2DX**: + A. Eclipse->Preferences->General->Workspace->**Linked Resources** + B. Click **New** button to add a Path Variable **COCOS2DX** pointing to the root cocos2d-x directory (Directory containing cocos2dx/ external/ tools/ scripting/ etc.). + + 2. C/C++ Environment Variable **NDK_ROOT**: + A. Eclipse->Preferences->General->C/C++->Build->**Environment**. + B. Click **Add** button and add a new variable **NDK_ROOT** pointing to the root NDK directory. + +3. Import libcocos2dx library project: + 1. File->new->Project..->Android Project From Existing Code. + 2. Click **Browse** button and open cocos2d-x/cocos2dx/platform/android/java directory. + 3. Click **Finish** to add project. + + + +#### Adding and running from Eclipse + + +1. File->new->Project..->Android Project From Existing Code +2. **Browse** to cocos2d-x/cocos2dx/projects/Name Of Project/proj.android/ directory. +3. Add the project +4. Click **Run** or **Debug** to compile C++ followed by Java and to run on connected device or emulator. + + +### Running project from Command Line + +1. `cd cocos2d-x/projects/Name Of Project/proj.android/` +2. `export NDK_ROOT=/path/to/ndk` +3. `./build_native.sh` +4. `ant debug install` +5. If step 4 results in sdk.dir missing error then follow step 6-8. +6. `android list target` +7. `android update project -p . -t (id from step 6)` +8. `android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6)` + + + + diff --git a/spine-cocos2dx/example/proj.android/ant.properties b/spine-cocos2dx/example/proj.android/ant.properties new file mode 100644 index 000000000..b0971e891 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/ant.properties @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked into Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff --git a/spine-cocos2dx/example/proj.android/build.xml b/spine-cocos2dx/example/proj.android/build.xml new file mode 100644 index 000000000..a669c78e1 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/build.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spine-cocos2dx/example/proj.android/build_native.sh b/spine-cocos2dx/example/proj.android/build_native.sh new file mode 100644 index 000000000..3f45b4d86 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/build_native.sh @@ -0,0 +1,79 @@ +APPNAME="SpineCocos2Dx" + +NDK_ROOT="[NDK PATH IN HERE]" + +# options + +buildexternalsfromsource= + +usage(){ +cat << EOF +usage: $0 [options] + +Build C/C++ code for $APPNAME using Android NDK + +OPTIONS: +-s Build externals from source +-h this help +EOF +} + +while getopts "sh" OPTION; do +case "$OPTION" in +s) +buildexternalsfromsource=1 +;; +h) +usage +exit 0 +;; +esac +done + +# paths + +if [ -z "${NDK_ROOT+aaa}" ];then +echo "please define NDK_ROOT" +exit 1 +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# ... use paths relative to current directory +COCOS2DX_ROOT="$DIR/../../../.." +APP_ROOT="$DIR/.." +APP_ANDROID_ROOT="$DIR" + +echo "NDK_ROOT = $NDK_ROOT" +echo "COCOS2DX_ROOT = $COCOS2DX_ROOT" +echo "APP_ROOT = $APP_ROOT" +echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT" + +# make sure assets is exist +if [ -d "$APP_ANDROID_ROOT"/assets ]; then + rm -rf "$APP_ANDROID_ROOT"/assets +fi + +mkdir "$APP_ANDROID_ROOT"/assets + +# copy resources +for file in "$APP_ROOT"/Resources/* +do +if [ -d "$file" ]; then + cp -rf "$file" "$APP_ANDROID_ROOT"/assets +fi + +if [ -f "$file" ]; then + cp "$file" "$APP_ANDROID_ROOT"/assets +fi +done + +# run ndk-build +if [[ "$buildexternalsfromsource" ]]; then + echo "Building external dependencies from source" + "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ + "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source" +else + echo "Using prebuilt externals" + "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ + "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt" +fi diff --git a/spine-cocos2dx/example/proj.android/jni/Android.mk b/spine-cocos2dx/example/proj.android/jni/Android.mk new file mode 100644 index 000000000..995f85315 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/jni/Android.mk @@ -0,0 +1,38 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := cocos2dcpp_shared + +LOCAL_MODULE_FILENAME := libcocos2dcpp + +# Sources +LOCAL_SRC_FILES := hellocpp/main.cpp \ + ../../Classes/AppDelegate.cpp \ + ../../Classes/ExampleLayer.cpp + +SRC_LIST := $(wildcard $(LOCAL_PATH)/../../../../../spine-runtimes/spine-c/src/spine/*.c) +LOCAL_SRC_FILES += $(SRC_LIST:$(LOCAL_PATH)/%=%) + +SRC_LIST := $(wildcard $(LOCAL_PATH)/../../../../../spine-runtimes/spine-cocos2dx/src/spine/*.cpp) +LOCAL_SRC_FILES += $(SRC_LIST:$(LOCAL_PATH)/%=%) + +# Headers +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ + ../../../../spine-runtimes/spine-c/include \ + ../../../../spine-runtimes/spine-cocos2dx/src + +LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static +#LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static +#LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static +#LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static +#LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static + +include $(BUILD_SHARED_LIBRARY) + +$(call import-module,cocos2dx) +#$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) +#$(call import-module,CocosDenshion/android) +#$(call import-module,extensions) +#$(call import-module,external/Box2D) +#$(call import-module,external/chipmunk) \ No newline at end of file diff --git a/spine-cocos2dx/example/proj.android/jni/Application.mk b/spine-cocos2dx/example/proj.android/jni/Application.mk new file mode 100644 index 000000000..743886713 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/jni/Application.mk @@ -0,0 +1,2 @@ +APP_STL := gnustl_static +APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1 diff --git a/spine-cocos2dx/example/proj.android/jni/hellocpp/main.cpp b/spine-cocos2dx/example/proj.android/jni/hellocpp/main.cpp new file mode 100644 index 000000000..8c51db510 --- /dev/null +++ b/spine-cocos2dx/example/proj.android/jni/hellocpp/main.cpp @@ -0,0 +1,45 @@ +#include "AppDelegate.h" +#include "cocos2d.h" +#include "CCEventType.h" +#include "platform/android/jni/JniHelper.h" +#include +#include + +#define LOG_TAG "main" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) + +using namespace cocos2d; + +extern "C" +{ + +jint JNI_OnLoad(JavaVM *vm, void *reserved) +{ + JniHelper::setJavaVM(vm); + + return JNI_VERSION_1_4; +} + +void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) +{ + if (!CCDirector::sharedDirector()->getOpenGLView()) + { + CCEGLView *view = CCEGLView::sharedOpenGLView(); + view->setFrameSize(w, h); + + AppDelegate *pAppDelegate = new AppDelegate(); + CCApplication::sharedApplication()->run(); + } + else + { + ccDrawInit(); + ccGLInvalidateStateCache(); + + CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); + CCTextureCache::reloadAllTextures(); + CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); + CCDirector::sharedDirector()->setGLDefaultValues(); + } +} + +} diff --git a/spine-cocos2dx/example/proj.android/proguard-project.txt b/spine-cocos2dx/example/proj.android/proguard-project.txt new file mode 100644 index 000000000..f2fe1559a --- /dev/null +++ b/spine-cocos2dx/example/proj.android/proguard-project.txt @@ -0,0 +1,20 @@ +# 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 *; +#} diff --git a/spine-cocos2dx/example/proj.android/project.properties b/spine-cocos2dx/example/proj.android/project.properties new file mode 100644 index 000000000..1d45f1ffd --- /dev/null +++ b/spine-cocos2dx/example/proj.android/project.properties @@ -0,0 +1,13 @@ +# 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 use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-8 + +android.library.reference.1=../../cocos2dx/platform/android/java diff --git a/spine-cocos2dx/example/proj.android/res/drawable-hdpi/icon.png b/spine-cocos2dx/example/proj.android/res/drawable-hdpi/icon.png new file mode 100644 index 000000000..8aa4767c2 Binary files /dev/null and b/spine-cocos2dx/example/proj.android/res/drawable-hdpi/icon.png differ diff --git a/spine-cocos2dx/example/proj.android/res/drawable-ldpi/icon.png b/spine-cocos2dx/example/proj.android/res/drawable-ldpi/icon.png new file mode 100644 index 000000000..17ce11a08 Binary files /dev/null and b/spine-cocos2dx/example/proj.android/res/drawable-ldpi/icon.png differ diff --git a/spine-cocos2dx/example/proj.android/res/drawable-mdpi/icon.png b/spine-cocos2dx/example/proj.android/res/drawable-mdpi/icon.png new file mode 100644 index 000000000..3780aac46 Binary files /dev/null and b/spine-cocos2dx/example/proj.android/res/drawable-mdpi/icon.png differ diff --git a/spine-cocos2dx/example/proj.android/res/values/strings.xml b/spine-cocos2dx/example/proj.android/res/values/strings.xml new file mode 100644 index 000000000..c2aa29feb --- /dev/null +++ b/spine-cocos2dx/example/proj.android/res/values/strings.xml @@ -0,0 +1,4 @@ + + + SpineCocos2Dx + diff --git a/spine-cocos2dx/example/proj.android/src/com/esotericsoftware/spinecocos2dx/SpineCocos2Dx.java b/spine-cocos2dx/example/proj.android/src/com/esotericsoftware/spinecocos2dx/SpineCocos2Dx.java new file mode 100644 index 000000000..c1fe5d83d --- /dev/null +++ b/spine-cocos2dx/example/proj.android/src/com/esotericsoftware/spinecocos2dx/SpineCocos2Dx.java @@ -0,0 +1,48 @@ +/**************************************************************************** +Copyright (c) 2010-2011 cocos2d-x.org + +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 com.esotericsoftware.spinecocos2dx; + +import org.cocos2dx.lib.Cocos2dxActivity; +import org.cocos2dx.lib.Cocos2dxGLSurfaceView; + +import android.os.Bundle; + +public class SpineCocos2Dx extends Cocos2dxActivity{ + + protected void onCreate(Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + } + + public Cocos2dxGLSurfaceView onCreateView() { + Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); + // SpineCocos2Dx should create stencil buffer + glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8); + + return glSurfaceView; + } + + static { + System.loadLibrary("cocos2dcpp"); + } +}